home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Other Langs / python / msgbox < prev    next >
Encoding:
Text File  |  1994-04-01  |  1.5 MB  |  41,763 lines  |  [TEXT/R*ch]

Text Truncated. Only the first 1MB is shown below. Download the file for the complete contents.
  1. 
  2. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3.     id AA20530 (5.65b/3.6/CWI-Amsterdam); Sat, 9 Jan 1993 21:31:07 +0100
  4. Received: by voorn.cwi.nl with SMTP
  5.     id AA04917 (5.65b/3.5/CWI-Amsterdam); Sat, 9 Jan 1993 21:31:05 +0100
  6. Message-Id: <9301092031.AA04917.guido@voorn.cwi.nl>
  7. To: python-list@cwi.nl
  8. Subject: Python 0.9.8 released
  9. From: Guido.van.Rossum@cwi.nl
  10. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  11. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  12. Date: Sat, 09 Jan 1993 21:31:04 +0100
  13. Sender: Guido.van.Rossum@cwi.nl
  14.  
  15. I have finally released the long-awaited Python version 0.9.8.  Boy
  16. has it been a heavy delivery!  But the baby is healthy as can be...
  17.  
  18. You can ftp it from the following sites:
  19.  
  20. Location    Site            IP address         Directory
  21.  
  22. Amsterdam    ftp.cwi.nl        192.16.184.180        /pub/python
  23. U.S.A.        wuarchive.wustl.edu    128.252.135.4        /pub
  24.  
  25. The filename is python0.9.8.tar.Z.  (Note the changed directory name
  26. on ftp.cwi.nl!)  There's also a file containing PostScript of the
  27. documentation (tutorial, reference, library): pythondoc-ps0.9.8.tar.Z.
  28. I'm sorry, there are no Mac or PC versions yet.
  29.  
  30. The version on wuarchive is likely to evaporate some time after it is
  31. installed; I will try to make sure that the version on ftp.cwi.nl is
  32. always there.  You are invited to copy these files to other ftp
  33. archives to which you have access.
  34.  
  35. Below is an exhaustive list of changes since 0.9.6 (which most of you
  36. are probably still using).
  37.  
  38. If you wonder what happened to 0.9.7: there was a 0.9.7beta, which
  39. was a little rough, and instead of polishing it up a bit, I went ahead
  40. and made many more changes, so eventually I felt myself forced to call
  41. it 0.9.8.
  42.  
  43. If you experience any kind of trouble with building or using 0.9.8,
  44. please mail a short description giving as much detail as possible
  45. about what system and configuration you are using and what kind of
  46. error messages you get, either to the list, or to me (if you fear it
  47. might be your own fault and don't want to be embarrassed).  In all
  48. cases I will try to do something about it, providing either a
  49. work-around or patch.
  50.  
  51. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  52.  
  53. ==============================
  54. ==> NEWS FOR RELEASE 0.9.8 <==
  55. ==============================
  56.  
  57. I claim no completeness here, but I've tried my best to scan the log
  58. files throughout my source tree for interesting bits of news.  A more
  59. complete account of the changes is to be found in the various
  60. ChangeLog files. See also "News for release 0.9.7beta" below if you're
  61. still using release 0.9.6, and the file HISTORY if you have an even
  62. older release.
  63.  
  64.     --Guido
  65.  
  66.  
  67. Changes to the language proper
  68. ------------------------------
  69.  
  70. There's only one big change: the conformance checking for function
  71. argument lists (of user-defined functions only) is stricter.  Earlier,
  72. you could get away with the following:
  73.  
  74.     (a) define a function of one argument and call it with any
  75.         number of arguments; if the actual argument count wasn't
  76.         one, the function would receive a tuple containing the
  77.         arguments arguments (an empty tuple if there were none).
  78.  
  79.     (b) define a function of two arguments, and call it with more
  80.         than two arguments; if there were more than two arguments,
  81.         the second argument would be passed as a tuple containing
  82.         the second and further actual arguments.
  83.  
  84. (Note that an argument (formal or actual) that is a tuple is counted as
  85. one; these rules don't apply inside such tuples, only at the top level
  86. of the argument list.)
  87.  
  88. Case (a) was needed to accommodate variable-length argument lists;
  89. there is now an explicit "varargs" feature (precede the last argument
  90. with a '*').  Case (b) was needed for compatibility with old class
  91. definitions: up to release 0.9.4 a method with more than one argument
  92. had to be declared as "def meth(self, (arg1, arg2, ...)): ...".
  93. Version 0.9.6 provide better ways to handle both casees, bot provided
  94. backward compatibility; version 0.9.8 retracts the compatibility hacks
  95. since they also cause confusing behavior if a function is called with
  96. the wrong number of arguments.
  97.  
  98. There's a script that helps converting classes that still rely on (b),
  99. provided their methods' first argument is called "self":
  100. demo/scripts/methfix.py.
  101.  
  102. If this change breaks lots of code you have developed locally, try
  103. #defining COMPAT_HACKS in ceval.c.
  104.  
  105. (There's a third compatibility hack, which is the reverse of (a): if a
  106. function is defined with two or more arguments, and called with a
  107. single argument that is a tuple with just as many arguments, the items
  108. of this tuple will be used as the arguments.  Although this can (and
  109. should!) be done using the built-in function apply() instead, it isn't
  110. withdrawn yet.)
  111.  
  112.  
  113. One minor change: comparing instance methods works like expected, so
  114. that if x is an instance of a user-defined class and has a method m,
  115. then (x.m==x.m) yields 1.
  116.  
  117.  
  118. The following was already present in 0.9.7beta, but not explicitly
  119. mentioned in the NEWS file: user-defined classes can now define types
  120. that behave in almost allrespects like numbers.  See
  121. demo/classes/Rat.py for a simple example.
  122.  
  123.  
  124. Changes to the build process
  125. ----------------------------
  126.  
  127. The Configure.py script and the Makefile has been made somewhat more
  128. bullet-proof, after reports of (minor) trouble on certain platforms.
  129.  
  130. There is now a script to patch Makefile and config.c to add a new
  131. optional built-in module: Addmodule.sh.  Read the script before using!
  132.  
  133. Useing Addmodule.sh, all optional modules can now be configured at
  134. compile time using Configure.py, so there are no modules left that
  135. require dynamic loading.
  136.  
  137. The Makefile has been fixed to make it easier to use with the VPATH
  138. feature of some Make versions (e.g. SunOS).
  139.  
  140.  
  141. Changes affecting portability
  142. -----------------------------
  143.  
  144. Several minor portability problems have been solved, e.g. "malloc.h"
  145. has been renamed to "mymalloc.h", "strdup.c" is no longer used, and
  146. the system now tolerates malloc(0) returning 0.
  147.  
  148. For dynamic loading on the SGI, Jack Jansen's dl 1.6 is now
  149. distributed with Python.  This solves several minor problems, in
  150. particular scripts invoked using #! can now use dynamic loading.
  151.  
  152.  
  153. Changes to the interpreter interface
  154. ------------------------------------
  155.  
  156. On popular demand, there's finally a "profile" feature for interactive
  157. use of the interpreter.  If the environment variable $PYTHONSTARTUP is
  158. set to the name of an existing file, Python statements in this file
  159. are executed when the interpreter is started in interactive mode.
  160.  
  161. There is a new clean-up mechanism, complementing try...finally: if you
  162. assign a function object to sys.exitfunc, it will be called when
  163. Python exits or receives a SIGTERM or SIGHUP signal.
  164.  
  165. The interpreter is now generally assumed to live in
  166. /usr/local/bin/python (as opposed to /usr/local/python).  The script
  167. demo/scripts/fixps.py will update old scripts in place (you can easily
  168. modify it to do other similar changes).
  169.  
  170. Most I/O that uses sys.stdin/stdout/stderr will now use any object
  171. assigned to those names as long as the object supports readline() or
  172. write() methods.
  173.  
  174. The parser stack has been increased to 500 to accommodate more
  175. complicated expressions (7 levels used to be the practical maximum,
  176. it's now about 38).
  177.  
  178. The limit on the size of the *run-time* stack has completely been
  179. removed -- this means that tuple or list displays can contain any
  180. number of elements (formerly more than 50 would crash the
  181. interpreter). 
  182.  
  183.  
  184. Changes to existing built-in functions and methods
  185. --------------------------------------------------
  186.  
  187. The built-in functions int(), long(), float(), oct() and hex() now
  188. also apply to class instalces that define corresponding methods
  189. (__int__ etc.).
  190.  
  191.  
  192. New built-in functions
  193. ----------------------
  194.  
  195. The new functions str() and repr() convert any object to a string.
  196. The function repr(x) is in all respects equivalent to `x` -- some
  197. people prefer a function for this.  The function str(x) does the same
  198. except if x is already a string -- then it returns x unchanged
  199. (repr(x) adds quotes and escapes "funny" characters as octal escapes).
  200.  
  201. The new function cmp(x, y) returns -1 if x<y, 0 if x==y, 1 if x>y.
  202.  
  203.  
  204. Changes to general built-in modules
  205. -----------------------------------
  206.  
  207. The time module's functions are more general: time() returns a
  208. floating point number and sleep() accepts one.  Their accuracies
  209. depends on the precision of the system clock.  Millisleep is no longer
  210. needed (although it still exists for now), but millitimer is still
  211. needed since on some systems wall clock time is only available with
  212. seconds precision, while a source of more precise time exists that
  213. isn't synchronized with the wall clock.  (On UNIX systems that support
  214. the BSD gettimeofday() function, time.time() is as time.millitimer().)
  215.  
  216. The string representation of a file object now includes an address:
  217. '<file 'filename', mode 'r' at #######>' where ###### is a hex number
  218. (the object's address) to make it unique.
  219.  
  220. New functions added to posix: nice(), setpgrp(), and if your system
  221. supports them: setsid(), setpgid(), tcgetpgrp(), tcsetpgrp().
  222.  
  223. Improvements to the socket module: socket objects have new methods
  224. getpeername() and getsockname(), and the {get,set}sockopt methods can
  225. now get/set any kind of option using strings built with the new struct
  226. module.  And there's a new function fromfd() which creates a socket
  227. object given a file descriptor (useful for servers started by inetd,
  228. which have a socket connected to stdin and stdout).
  229.  
  230.  
  231. Changes to SGI-specific built-in modules
  232. ----------------------------------------
  233.  
  234. The FORMS library interface (fl) now requires FORMS 2.1a.  Some new
  235. functions have been added and some bugs have been fixed.
  236.  
  237. Additions to al (audio library interface): added getname(),
  238. getdefault() and getminmax().
  239.  
  240. The gl modules doesn't call "foreground()" when initialized (this
  241. caused some problems) like it dit in 0.9.7beta (but not before).
  242. There's a new gl function 'gversion() which returns a version string.
  243.  
  244. The interface to sv (Indigo video interface) has totally changed.
  245. (Sorry, still no documentation, but see the examples in
  246. demo/sgi/{sv,video}.)
  247.  
  248.  
  249. Changes to standard library modules
  250. -----------------------------------
  251.  
  252. Most functions in module string are now much faster: they're actually
  253. implemented in C.  The module containing the C versions is called
  254. "strop" but you should still import "string" since strop doesn't
  255. provide all the interfaces defined in string (and strop may be renamed
  256. to string when it is complete in a future release).
  257.  
  258. string.index() now accepts an optional third argument giving an index
  259. where to start searching in the first argument, so you can find second
  260. and further occurrences (this is similar to the regular expression
  261. functions in regex).
  262.  
  263. The definition of what string.splitfields(anything, '') should return
  264. is changed for the last time: it returns a singleton list containing
  265. its whole first argument unchanged.  This is compatible with
  266. regsub.split() which also ignores empty delimiter matches.
  267.  
  268. posixpath, macpath: added dirname() and normpath() (and basename() to
  269. macpath).
  270.  
  271. The mainloop module (for use with stdwin) can now demultiplex input
  272. from other sources, as long as they can be polled with select().
  273.  
  274.  
  275. New built-in modules
  276. --------------------
  277.  
  278. Module struct defines functions to pack/unpack values to/from strings
  279. representing binary values in native byte order.
  280.  
  281. Module strop implements C versions of many functions from string (see
  282. above).
  283.  
  284. Optional module fcntl defines interfaces to fcntl() and ioctl() --
  285. UNIX only.  (Not yet properly documented -- see however src/fcntl.doc.)
  286.  
  287. Optional module mpz defines an interface to an altaernative long
  288. integer implementation, the GNU MPZ library.
  289.  
  290. Optional module md5 uses the GNU MPZ library to calculate MD5
  291. signatures of strings.
  292.  
  293. There are also optional new modules specific to SGI machines: imageop
  294. defines some simple operations to images represented as strings; sv
  295. interfaces to the Indigo video board; cl interfaces to the (yet
  296. unreleased) compression library.
  297.  
  298.  
  299. New standard library modules
  300. ----------------------------
  301.  
  302. (Unfortunately the following modules are not all documented; read the
  303. sources to find out more about them!)
  304.  
  305. autotest: run testall without showing any output unless it differs
  306. from the expected output
  307.  
  308. bisect: use bisection to insert or find an item in a sorted list
  309.  
  310. colorsys: defines conversions between various color systems (e.g. RGB
  311. <-> YUV)
  312.  
  313. nntplib: a client interface to NNTP servers
  314.  
  315. pipes: utility to construct pipeline from templates, e.g. for
  316. conversion from one file format to another using several utilities.
  317.  
  318. regsub: contains three functions that are more or less compatible with
  319. awk functions of the same name: sub() and gsub() do string
  320. substitution, split() splits a string using a regular expression to
  321. define how separators are define.
  322.  
  323. test_types: test operations on the built-in types of Python
  324.  
  325. toaiff: convert various audio file formats to AIFF format
  326.  
  327. tzparse: parse the TZ environment parameter (this may be less general
  328. than it could be, let me know if you fix it).
  329.  
  330. (Note that the obsolete module "path" no longer exists.)
  331.  
  332.  
  333. New SGI-specific library modules
  334. --------------------------------
  335.  
  336. CL: constants for use with the built-in compression library interface (cl)
  337.  
  338. Queue: a multi-producer, multi-consumer queue class implemented for
  339. use with the built-in thread module
  340.  
  341. SOCKET: constants for use with built-in module socket, e.g. to set/get
  342. socket options.  This is SGI-specific because the constants to be
  343. passed are system-dependent.  You can generate a version for your own
  344. system by running the script demo/scripts/h2py.py with
  345. /usr/include/sys/socket.h as input.
  346.  
  347. cddb: interface to the database used the the CD player
  348.  
  349. torgb: convert various image file types to rgb format (requires pbmplus)
  350.  
  351.  
  352. New demos
  353. ---------
  354.  
  355. There's an experimental interface to define Sun RPC clients and
  356. servers in demo/rpc.
  357.  
  358. There's a collection of interfaces to WWW, WAIS and Gopher (both
  359. Python classes and program providing a user interface) in demo/www.
  360. This includes a program texi2html.py which converts texinfo files to
  361. HTML files (the format used hy WWW).
  362.  
  363. The ibrowse demo has moved from demo/stdwin/ibrowse to demo/ibrowse.
  364.  
  365. For SGI systems, there's a whole collection of programs and classes
  366. that make use of the Indigo video board in demo/sgi/{sv,video}.  This
  367. represents a significant amount of work that we're giving away!
  368.  
  369. There are demos "rsa" and "md5test" that exercise the mpz and md5
  370. modules, respectively.  The rsa demo is a complete implementation of
  371. the RSA public-key cryptosystem!
  372.  
  373. A bunch of games and examples submitted by Stoffel Erasmus have been
  374. included in demo/stoffel.
  375.  
  376. There are miscellaneous new files in some existing demo
  377. subdirectories: classes/bitvec.py, scripts/{fixps,methfix}.py,
  378. sgi/al/cmpaf.py, sockets/{mcast,gopher}.py.
  379.  
  380. There are also many minor changes to existing files, but I'm too lazy
  381. to run a diff and note the differences -- you can do this yourself if
  382. you save the old distribution's demos.  One highlight: the
  383. stdwin/python.py demo is much improved!
  384.  
  385.  
  386. Changes to the documentation
  387. ----------------------------
  388.  
  389. The LaTeX source for the library uses different macros to enable it to
  390. be converted to texinfo, and from there to INFO or HTML format so it
  391. can be browsed as a hypertext.  The net result is that you can now
  392. read the Python library documentation in Emacs info mode!
  393.  
  394.  
  395. Changes to the source code that affect C extension writers
  396. ----------------------------------------------------------
  397.  
  398. The function strdup() no longer exists (it was used only in one places
  399. and is somewhat of a a portability problem sice some systems have the
  400. same function in their C library.
  401.  
  402. The functions NEW() and RENEW() allocate one spare byte to guard
  403. against a NULL return from malloc(0) being taken for an error, but
  404. this should not be relied upon.
  405.  
  406.  
  407. ==================================
  408. ==> NEWS FOR RELEASE 0.9.7beta <==
  409. ==================================
  410.  
  411.  
  412. Changes to the language proper
  413. ------------------------------
  414.  
  415. User-defined classes can now implement operations invoked through
  416. special syntax, such as x[i] or `x` by defining methods named
  417. __getitem__(self, i) or __repr__(self), etc.
  418.  
  419.  
  420. Changes to the build process
  421. ----------------------------
  422.  
  423. Instead of extensive manual editing of the Makefile to select
  424. compile-time options, you can now run a Configure.py script.
  425. The Makefile as distributed builds a minimal interpreter sufficient to
  426. run Configure.py.  See also misc/BUILD
  427.  
  428. The Makefile now includes more "utility" targets, e.g. install and
  429. tags/TAGS
  430.  
  431. Using the provided strtod.c and strtol.c are now separate options, as
  432. on the Sun the provided strtod.c dumps core :-(
  433.  
  434. The regex module is now an option chosen by the Makefile, since some
  435. (old) C compilers choke on regexpr.c
  436.  
  437.  
  438. Changes affecting portability
  439. -----------------------------
  440.  
  441. You need STDWIN version 0.9.7 (released 30 June 1992) for the stdwin
  442. interface
  443.  
  444. Dynamic loading is now supported for Sun (and other non-COFF systems)
  445. throug dld-3.2.3, as well as for SGI (a new version of Jack Jansen's
  446. DL is out, 1.4)
  447.  
  448. The system-dependent code for the use of the select() system call is
  449. moved to one file: myselect.h
  450.  
  451. Thanks to Jaap Vermeulen, the code should now port cleanly to the
  452. SEQUENT
  453.  
  454.  
  455. Changes to the interpreter interface
  456. ------------------------------------
  457.  
  458. The interpretation of $PYTHONPATH in the environment is different: it
  459. is inserted in front of the default path instead of overriding it
  460.  
  461.  
  462. Changes to existing built-in functions and methods
  463. --------------------------------------------------
  464.  
  465. List objects now support an optional argument to their sort() method,
  466. which is a comparison function similar to qsort(3) in C
  467.  
  468. File objects now have a method fileno(), used by the new select module
  469. (see below)
  470.  
  471.  
  472. New built-in function
  473. ---------------------
  474.  
  475. coerce(x, y): take two numbers and return a tuple containing them
  476. both converted to a common type
  477.  
  478.  
  479. Changes to built-in modules
  480. ---------------------------
  481.  
  482. sys: fixed core dumps in settrace() and setprofile()
  483.  
  484. socket: added socket methods setsockopt() and getsockopt(); and
  485. fileno(), used by the new select module (see below)
  486.  
  487. stdwin: added fileno() == connectionnumber(), in support of new module
  488. select (see below)
  489.  
  490. posix: added get{eg,eu,g,u}id(); waitpid() is now a separate function.
  491.  
  492. gl: added qgetfd()
  493.  
  494. fl: added several new functions, fixed several obscure bugs, adapted
  495. to FORMS 2.1
  496.  
  497.  
  498. Changes to standard modules
  499. ---------------------------
  500.  
  501. posixpath: changed implementation of ismount()
  502.  
  503. string: atoi() no longer mistakes leading zero for octal number
  504.  
  505. ...
  506.  
  507.  
  508. New built-in modules
  509. --------------------
  510.  
  511. Modules marked "dynamic only" are not configured at compile time but
  512. can be loaded dynamically.  You need to turn on the DL or DLD option in
  513. the Makefile for support dynamic loading of modules (this requires
  514. external code).
  515.  
  516. select: interfaces to the BSD select() system call
  517.  
  518. dbm: interfaces to the (new) dbm library (dynamic only)
  519.  
  520. nis: interfaces to some NIS functions (aka yellow pages)
  521.  
  522. thread: limited form of multiple threads (sgi only)
  523.  
  524. audioop: operations useful for audio programs, e.g. u-LAW and ADPCM
  525. coding (dynamic only)
  526.  
  527. cd: interface to Indigo SCSI CDROM player audio library (sgi only)
  528.  
  529. jpeg: read files in JPEG format (dynamic only, sgi only; needs
  530. external code)
  531.  
  532. imgfile: read SGI image files (dynamic only, sgi only)
  533.  
  534. sunaudiodev: interface to sun's /dev/audio (dynamic only, sun only)
  535.  
  536. sv: interface to Indigo video library (sgi only)
  537.  
  538. pc: a minimal set of MS-DOS interfaces (MS-DOS only)
  539.  
  540. rotor: encryption, by Lance Ellinghouse (dynamic only)
  541.  
  542.  
  543. New standard modules
  544. --------------------
  545.  
  546. Not all these modules are documented.  Read the source:
  547. lib/<modulename>.py.  Sometimes a file lib/<modulename>.doc contains
  548. additional documentation.
  549.  
  550. imghdr: recognizes image file headers
  551.  
  552. sndhdr: recognizes sound file headers
  553.  
  554. profile: print run-time statistics of Python code
  555.  
  556. readcd, cdplayer: companion modules for built-in module cd (sgi only)
  557.  
  558. emacs: interface to Emacs using py-connect.el (see below).
  559.  
  560. SOCKET: symbolic constant definitions for socket options
  561.  
  562. SUNAUDIODEV: symbolic constant definitions for sunaudiodef (sun only)
  563.  
  564. SV: symbolic constat definitions for sv (sgi only)
  565.  
  566. CD: symbolic constat definitions for cd (sgi only)
  567.  
  568.  
  569. New demos
  570. ---------
  571.  
  572. scripts/pp.py: execute Python as a filter with a Perl-like command
  573. line interface
  574.  
  575. classes/: examples using the new class features
  576.  
  577. threads/: examples using the new thread module
  578.  
  579. sgi/cd/: examples using the new cd module
  580.  
  581.  
  582. Changes to the documentation
  583. ----------------------------
  584.  
  585. The last-minute syntax changes of release 0.9.6 are now reflected
  586. everywhere in the manuals
  587.  
  588. The reference manual has a new section (3.2) on implementing new kinds
  589. of numbers, sequences or mappings with user classes
  590.  
  591. Classes are now treated extensively in the tutorial (chapter 9)
  592.  
  593. Slightly restructured the system-dependent chapters of the library
  594. manual
  595.  
  596. The file misc/EXTENDING incorporates documentation for mkvalue() and
  597. a new section on error handling
  598.  
  599. The files misc/CLASSES and misc/ERRORS are no longer necessary
  600.  
  601. The doc/Makefile now creates PostScript files automatically
  602.  
  603.  
  604. Miscellaneous changes
  605. ---------------------
  606.  
  607. Incorporated Tim Peters' changes to python-mode.el, it's now version
  608. 1.06
  609.  
  610. A python/Emacs bridge (provided by Terrence M. Brannon) lets a Python
  611. program running in an Emacs buffer execute Emacs lisp code.  The
  612. necessary Python code is in lib/emacs.py.  The Emacs code is
  613. misc/py-connect.el (it needs some external Emacs lisp code)
  614.  
  615.  
  616. Changes to the source code that affect C extension writers
  617. ----------------------------------------------------------
  618.  
  619. New service function mkvalue() to construct a Python object from C
  620. values according to a "format" string a la getargs()
  621.  
  622. Most functions from pythonmain.c moved to new pythonrun.c which is
  623. in libpython.a.  This should make embedded versions of Python easier
  624.  
  625. ceval.h is split in eval.h (which needs compile.h and only declares
  626. eval_code) and ceval.h (which doesn't need compile.hand declares the
  627. rest)
  628.  
  629. ceval.h defines macros BGN_SAVE / END_SAVE for use with threads (to
  630. improve the parallellism of multi-threaded programs by letting other
  631. Python code run when a blocking system call or something similar is
  632. made)
  633.  
  634. In structmember.[ch], new member types BYTE, CHAR and unsigned
  635. variants have been added
  636.  
  637. New file xxmodule.c is a template for new extension modules.
  638. 
  639. 
  640. To: python-list
  641. Subject: Python 0.9.8 released
  642. From: Guido.van.Rossum@cwi.nl
  643. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  644. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  645. Date: Sat, 09 Jan 1993 21:31:04 +0100
  646. Sender: guido
  647.  
  648. I have finally released the long-awaited Python version 0.9.8.  Boy
  649. has it been a heavy delivery!  But the baby is healthy as can be...
  650.  
  651. You can ftp it from the following sites:
  652.  
  653. Location    Site            IP address         Directory
  654.  
  655. Amsterdam    ftp.cwi.nl        192.16.184.180        /pub/python
  656. U.S.A.        wuarchive.wustl.edu    128.252.135.4        /pub
  657.  
  658. The filename is python0.9.8.tar.Z.  (Note the changed directory name
  659. on ftp.cwi.nl!)  There's also a file containing PostScript of the
  660. documentation (tutorial, reference, library): pythondoc-ps0.9.8.tar.Z.
  661. I'm sorry, there are no Mac or PC versions yet.
  662.  
  663. The version on wuarchive is likely to evaporate some time after it is
  664. installed; I will try to make sure that the version on ftp.cwi.nl is
  665. always there.  You are invited to copy these files to other ftp
  666. archives to which you have access.
  667.  
  668. Below is an exhaustive list of changes since 0.9.6 (which most of you
  669. are probably still using).
  670.  
  671. If you wonder what happened to 0.9.7: there was a 0.9.7beta, which
  672. was a little rough, and instead of polishing it up a bit, I went ahead
  673. and made many more changes, so eventually I felt myself forced to call
  674. it 0.9.8.
  675.  
  676. If you experience any kind of trouble with building or using 0.9.8,
  677. please mail a short description giving as much detail as possible
  678. about what system and configuration you are using and what kind of
  679. error messages you get, either to the list, or to me (if you fear it
  680. might be your own fault and don't want to be embarrassed).  In all
  681. cases I will try to do something about it, providing either a
  682. work-around or patch.
  683.  
  684. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  685.  
  686. ==============================
  687. ==> NEWS FOR RELEASE 0.9.8 <==
  688. ==============================
  689.  
  690. I claim no completeness here, but I've tried my best to scan the log
  691. files throughout my source tree for interesting bits of news.  A more
  692. complete account of the changes is to be found in the various
  693. ChangeLog files. See also "News for release 0.9.7beta" below if you're
  694. still using release 0.9.6, and the file HISTORY if you have an even
  695. older release.
  696.  
  697.     --Guido
  698.  
  699.  
  700. Changes to the language proper
  701. ------------------------------
  702.  
  703. There's only one big change: the conformance checking for function
  704. argument lists (of user-defined functions only) is stricter.  Earlier,
  705. you could get away with the following:
  706.  
  707.     (a) define a function of one argument and call it with any
  708.         number of arguments; if the actual argument count wasn't
  709.         one, the function would receive a tuple containing the
  710.         arguments arguments (an empty tuple if there were none).
  711.  
  712.     (b) define a function of two arguments, and call it with more
  713.         than two arguments; if there were more than two arguments,
  714.         the second argument would be passed as a tuple containing
  715.         the second and further actual arguments.
  716.  
  717. (Note that an argument (formal or actual) that is a tuple is counted as
  718. one; these rules don't apply inside such tuples, only at the top level
  719. of the argument list.)
  720.  
  721. Case (a) was needed to accommodate variable-length argument lists;
  722. there is now an explicit "varargs" feature (precede the last argument
  723. with a '*').  Case (b) was needed for compatibility with old class
  724. definitions: up to release 0.9.4 a method with more than one argument
  725. had to be declared as "def meth(self, (arg1, arg2, ...)): ...".
  726. Version 0.9.6 provide better ways to handle both casees, bot provided
  727. backward compatibility; version 0.9.8 retracts the compatibility hacks
  728. since they also cause confusing behavior if a function is called with
  729. the wrong number of arguments.
  730.  
  731. There's a script that helps converting classes that still rely on (b),
  732. provided their methods' first argument is called "self":
  733. demo/scripts/methfix.py.
  734.  
  735. If this change breaks lots of code you have developed locally, try
  736. #defining COMPAT_HACKS in ceval.c.
  737.  
  738. (There's a third compatibility hack, which is the reverse of (a): if a
  739. function is defined with two or more arguments, and called with a
  740. single argument that is a tuple with just as many arguments, the items
  741. of this tuple will be used as the arguments.  Although this can (and
  742. should!) be done using the built-in function apply() instead, it isn't
  743. withdrawn yet.)
  744.  
  745.  
  746. One minor change: comparing instance methods works like expected, so
  747. that if x is an instance of a user-defined class and has a method m,
  748. then (x.m==x.m) yields 1.
  749.  
  750.  
  751. The following was already present in 0.9.7beta, but not explicitly
  752. mentioned in the NEWS file: user-defined classes can now define types
  753. that behave in almost allrespects like numbers.  See
  754. demo/classes/Rat.py for a simple example.
  755.  
  756.  
  757. Changes to the build process
  758. ----------------------------
  759.  
  760. The Configure.py script and the Makefile has been made somewhat more
  761. bullet-proof, after reports of (minor) trouble on certain platforms.
  762.  
  763. There is now a script to patch Makefile and config.c to add a new
  764. optional built-in module: Addmodule.sh.  Read the script before using!
  765.  
  766. Useing Addmodule.sh, all optional modules can now be configured at
  767. compile time using Configure.py, so there are no modules left that
  768. require dynamic loading.
  769.  
  770. The Makefile has been fixed to make it easier to use with the VPATH
  771. feature of some Make versions (e.g. SunOS).
  772.  
  773.  
  774. Changes affecting portability
  775. -----------------------------
  776.  
  777. Several minor portability problems have been solved, e.g. "malloc.h"
  778. has been renamed to "mymalloc.h", "strdup.c" is no longer used, and
  779. the system now tolerates malloc(0) returning 0.
  780.  
  781. For dynamic loading on the SGI, Jack Jansen's dl 1.6 is now
  782. distributed with Python.  This solves several minor problems, in
  783. particular scripts invoked using #! can now use dynamic loading.
  784.  
  785.  
  786. Changes to the interpreter interface
  787. ------------------------------------
  788.  
  789. On popular demand, there's finally a "profile" feature for interactive
  790. use of the interpreter.  If the environment variable $PYTHONSTARTUP is
  791. set to the name of an existing file, Python statements in this file
  792. are executed when the interpreter is started in interactive mode.
  793.  
  794. There is a new clean-up mechanism, complementing try...finally: if you
  795. assign a function object to sys.exitfunc, it will be called when
  796. Python exits or receives a SIGTERM or SIGHUP signal.
  797.  
  798. The interpreter is now generally assumed to live in
  799. /usr/local/bin/python (as opposed to /usr/local/python).  The script
  800. demo/scripts/fixps.py will update old scripts in place (you can easily
  801. modify it to do other similar changes).
  802.  
  803. Most I/O that uses sys.stdin/stdout/stderr will now use any object
  804. assigned to those names as long as the object supports readline() or
  805. write() methods.
  806.  
  807. The parser stack has been increased to 500 to accommodate more
  808. complicated expressions (7 levels used to be the practical maximum,
  809. it's now about 38).
  810.  
  811. The limit on the size of the *run-time* stack has completely been
  812. removed -- this means that tuple or list displays can contain any
  813. number of elements (formerly more than 50 would crash the
  814. interpreter). 
  815.  
  816.  
  817. Changes to existing built-in functions and methods
  818. --------------------------------------------------
  819.  
  820. The built-in functions int(), long(), float(), oct() and hex() now
  821. also apply to class instalces that define corresponding methods
  822. (__int__ etc.).
  823.  
  824.  
  825. New built-in functions
  826. ----------------------
  827.  
  828. The new functions str() and repr() convert any object to a string.
  829. The function repr(x) is in all respects equivalent to `x` -- some
  830. people prefer a function for this.  The function str(x) does the same
  831. except if x is already a string -- then it returns x unchanged
  832. (repr(x) adds quotes and escapes "funny" characters as octal escapes).
  833.  
  834. The new function cmp(x, y) returns -1 if x<y, 0 if x==y, 1 if x>y.
  835.  
  836.  
  837. Changes to general built-in modules
  838. -----------------------------------
  839.  
  840. The time module's functions are more general: time() returns a
  841. floating point number and sleep() accepts one.  Their accuracies
  842. depends on the precision of the system clock.  Millisleep is no longer
  843. needed (although it still exists for now), but millitimer is still
  844. needed since on some systems wall clock time is only available with
  845. seconds precision, while a source of more precise time exists that
  846. isn't synchronized with the wall clock.  (On UNIX systems that support
  847. the BSD gettimeofday() function, time.time() is as time.millitimer().)
  848.  
  849. The string representation of a file object now includes an address:
  850. '<file 'filename', mode 'r' at #######>' where ###### is a hex number
  851. (the object's address) to make it unique.
  852.  
  853. New functions added to posix: nice(), setpgrp(), and if your system
  854. supports them: setsid(), setpgid(), tcgetpgrp(), tcsetpgrp().
  855.  
  856. Improvements to the socket module: socket objects have new methods
  857. getpeername() and getsockname(), and the {get,set}sockopt methods can
  858. now get/set any kind of option using strings built with the new struct
  859. module.  And there's a new function fromfd() which creates a socket
  860. object given a file descriptor (useful for servers started by inetd,
  861. which have a socket connected to stdin and stdout).
  862.  
  863.  
  864. Changes to SGI-specific built-in modules
  865. ----------------------------------------
  866.  
  867. The FORMS library interface (fl) now requires FORMS 2.1a.  Some new
  868. functions have been added and some bugs have been fixed.
  869.  
  870. Additions to al (audio library interface): added getname(),
  871. getdefault() and getminmax().
  872.  
  873. The gl modules doesn't call "foreground()" when initialized (this
  874. caused some problems) like it dit in 0.9.7beta (but not before).
  875. There's a new gl function 'gversion() which returns a version string.
  876.  
  877. The interface to sv (Indigo video interface) has totally changed.
  878. (Sorry, still no documentation, but see the examples in
  879. demo/sgi/{sv,video}.)
  880.  
  881.  
  882. Changes to standard library modules
  883. -----------------------------------
  884.  
  885. Most functions in module string are now much faster: they're actually
  886. implemented in C.  The module containing the C versions is called
  887. "strop" but you should still import "string" since strop doesn't
  888. provide all the interfaces defined in string (and strop may be renamed
  889. to string when it is complete in a future release).
  890.  
  891. string.index() now accepts an optional third argument giving an index
  892. where to start searching in the first argument, so you can find second
  893. and further occurrences (this is similar to the regular expression
  894. functions in regex).
  895.  
  896. The definition of what string.splitfields(anything, '') should return
  897. is changed for the last time: it returns a singleton list containing
  898. its whole first argument unchanged.  This is compatible with
  899. regsub.split() which also ignores empty delimiter matches.
  900.  
  901. posixpath, macpath: added dirname() and normpath() (and basename() to
  902. macpath).
  903.  
  904. The mainloop module (for use with stdwin) can now demultiplex input
  905. from other sources, as long as they can be polled with select().
  906.  
  907.  
  908. New built-in modules
  909. --------------------
  910.  
  911. Module struct defines functions to pack/unpack values to/from strings
  912. representing binary values in native byte order.
  913.  
  914. Module strop implements C versions of many functions from string (see
  915. above).
  916.  
  917. Optional module fcntl defines interfaces to fcntl() and ioctl() --
  918. UNIX only.  (Not yet properly documented -- see however src/fcntl.doc.)
  919.  
  920. Optional module mpz defines an interface to an altaernative long
  921. integer implementation, the GNU MPZ library.
  922.  
  923. Optional module md5 uses the GNU MPZ library to calculate MD5
  924. signatures of strings.
  925.  
  926. There are also optional new modules specific to SGI machines: imageop
  927. defines some simple operations to images represented as strings; sv
  928. interfaces to the Indigo video board; cl interfaces to the (yet
  929. unreleased) compression library.
  930.  
  931.  
  932. New standard library modules
  933. ----------------------------
  934.  
  935. (Unfortunately the following modules are not all documented; read the
  936. sources to find out more about them!)
  937.  
  938. autotest: run testall without showing any output unless it differs
  939. from the expected output
  940.  
  941. bisect: use bisection to insert or find an item in a sorted list
  942.  
  943. colorsys: defines conversions between various color systems (e.g. RGB
  944. <-> YUV)
  945.  
  946. nntplib: a client interface to NNTP servers
  947.  
  948. pipes: utility to construct pipeline from templates, e.g. for
  949. conversion from one file format to another using several utilities.
  950.  
  951. regsub: contains three functions that are more or less compatible with
  952. awk functions of the same name: sub() and gsub() do string
  953. substitution, split() splits a string using a regular expression to
  954. define how separators are define.
  955.  
  956. test_types: test operations on the built-in types of Python
  957.  
  958. toaiff: convert various audio file formats to AIFF format
  959.  
  960. tzparse: parse the TZ environment parameter (this may be less general
  961. than it could be, let me know if you fix it).
  962.  
  963. (Note that the obsolete module "path" no longer exists.)
  964.  
  965.  
  966. New SGI-specific library modules
  967. --------------------------------
  968.  
  969. CL: constants for use with the built-in compression library interface (cl)
  970.  
  971. Queue: a multi-producer, multi-consumer queue class implemented for
  972. use with the built-in thread module
  973.  
  974. SOCKET: constants for use with built-in module socket, e.g. to set/get
  975. socket options.  This is SGI-specific because the constants to be
  976. passed are system-dependent.  You can generate a version for your own
  977. system by running the script demo/scripts/h2py.py with
  978. /usr/include/sys/socket.h as input.
  979.  
  980. cddb: interface to the database used the the CD player
  981.  
  982. torgb: convert various image file types to rgb format (requires pbmplus)
  983.  
  984.  
  985. New demos
  986. ---------
  987.  
  988. There's an experimental interface to define Sun RPC clients and
  989. servers in demo/rpc.
  990.  
  991. There's a collection of interfaces to WWW, WAIS and Gopher (both
  992. Python classes and program providing a user interface) in demo/www.
  993. This includes a program texi2html.py which converts texinfo files to
  994. HTML files (the format used hy WWW).
  995.  
  996. The ibrowse demo has moved from demo/stdwin/ibrowse to demo/ibrowse.
  997.  
  998. For SGI systems, there's a whole collection of programs and classes
  999. that make use of the Indigo video board in demo/sgi/{sv,video}.  This
  1000. represents a significant amount of work that we're giving away!
  1001.  
  1002. There are demos "rsa" and "md5test" that exercise the mpz and md5
  1003. modules, respectively.  The rsa demo is a complete implementation of
  1004. the RSA public-key cryptosystem!
  1005.  
  1006. A bunch of games and examples submitted by Stoffel Erasmus have been
  1007. included in demo/stoffel.
  1008.  
  1009. There are miscellaneous new files in some existing demo
  1010. subdirectories: classes/bitvec.py, scripts/{fixps,methfix}.py,
  1011. sgi/al/cmpaf.py, sockets/{mcast,gopher}.py.
  1012.  
  1013. There are also many minor changes to existing files, but I'm too lazy
  1014. to run a diff and note the differences -- you can do this yourself if
  1015. you save the old distribution's demos.  One highlight: the
  1016. stdwin/python.py demo is much improved!
  1017.  
  1018.  
  1019. Changes to the documentation
  1020. ----------------------------
  1021.  
  1022. The LaTeX source for the library uses different macros to enable it to
  1023. be converted to texinfo, and from there to INFO or HTML format so it
  1024. can be browsed as a hypertext.  The net result is that you can now
  1025. read the Python library documentation in Emacs info mode!
  1026.  
  1027.  
  1028. Changes to the source code that affect C extension writers
  1029. ----------------------------------------------------------
  1030.  
  1031. The function strdup() no longer exists (it was used only in one places
  1032. and is somewhat of a a portability problem sice some systems have the
  1033. same function in their C library.
  1034.  
  1035. The functions NEW() and RENEW() allocate one spare byte to guard
  1036. against a NULL return from malloc(0) being taken for an error, but
  1037. this should not be relied upon.
  1038.  
  1039.  
  1040. ==================================
  1041. ==> NEWS FOR RELEASE 0.9.7beta <==
  1042. ==================================
  1043.  
  1044.  
  1045. Changes to the language proper
  1046. ------------------------------
  1047.  
  1048. User-defined classes can now implement operations invoked through
  1049. special syntax, such as x[i] or `x` by defining methods named
  1050. __getitem__(self, i) or __repr__(self), etc.
  1051.  
  1052.  
  1053. Changes to the build process
  1054. ----------------------------
  1055.  
  1056. Instead of extensive manual editing of the Makefile to select
  1057. compile-time options, you can now run a Configure.py script.
  1058. The Makefile as distributed builds a minimal interpreter sufficient to
  1059. run Configure.py.  See also misc/BUILD
  1060.  
  1061. The Makefile now includes more "utility" targets, e.g. install and
  1062. tags/TAGS
  1063.  
  1064. Using the provided strtod.c and strtol.c are now separate options, as
  1065. on the Sun the provided strtod.c dumps core :-(
  1066.  
  1067. The regex module is now an option chosen by the Makefile, since some
  1068. (old) C compilers choke on regexpr.c
  1069.  
  1070.  
  1071. Changes affecting portability
  1072. -----------------------------
  1073.  
  1074. You need STDWIN version 0.9.7 (released 30 June 1992) for the stdwin
  1075. interface
  1076.  
  1077. Dynamic loading is now supported for Sun (and other non-COFF systems)
  1078. throug dld-3.2.3, as well as for SGI (a new version of Jack Jansen's
  1079. DL is out, 1.4)
  1080.  
  1081. The system-dependent code for the use of the select() system call is
  1082. moved to one file: myselect.h
  1083.  
  1084. Thanks to Jaap Vermeulen, the code should now port cleanly to the
  1085. SEQUENT
  1086.  
  1087.  
  1088. Changes to the interpreter interface
  1089. ------------------------------------
  1090.  
  1091. The interpretation of $PYTHONPATH in the environment is different: it
  1092. is inserted in front of the default path instead of overriding it
  1093.  
  1094.  
  1095. Changes to existing built-in functions and methods
  1096. --------------------------------------------------
  1097.  
  1098. List objects now support an optional argument to their sort() method,
  1099. which is a comparison function similar to qsort(3) in C
  1100.  
  1101. File objects now have a method fileno(), used by the new select module
  1102. (see below)
  1103.  
  1104.  
  1105. New built-in function
  1106. ---------------------
  1107.  
  1108. coerce(x, y): take two numbers and return a tuple containing them
  1109. both converted to a common type
  1110.  
  1111.  
  1112. Changes to built-in modules
  1113. ---------------------------
  1114.  
  1115. sys: fixed core dumps in settrace() and setprofile()
  1116.  
  1117. socket: added socket methods setsockopt() and getsockopt(); and
  1118. fileno(), used by the new select module (see below)
  1119.  
  1120. stdwin: added fileno() == connectionnumber(), in support of new module
  1121. select (see below)
  1122.  
  1123. posix: added get{eg,eu,g,u}id(); waitpid() is now a separate function.
  1124.  
  1125. gl: added qgetfd()
  1126.  
  1127. fl: added several new functions, fixed several obscure bugs, adapted
  1128. to FORMS 2.1
  1129.  
  1130.  
  1131. Changes to standard modules
  1132. ---------------------------
  1133.  
  1134. posixpath: changed implementation of ismount()
  1135.  
  1136. string: atoi() no longer mistakes leading zero for octal number
  1137.  
  1138. ...
  1139.  
  1140.  
  1141. New built-in modules
  1142. --------------------
  1143.  
  1144. Modules marked "dynamic only" are not configured at compile time but
  1145. can be loaded dynamically.  You need to turn on the DL or DLD option in
  1146. the Makefile for support dynamic loading of modules (this requires
  1147. external code).
  1148.  
  1149. select: interfaces to the BSD select() system call
  1150.  
  1151. dbm: interfaces to the (new) dbm library (dynamic only)
  1152.  
  1153. nis: interfaces to some NIS functions (aka yellow pages)
  1154.  
  1155. thread: limited form of multiple threads (sgi only)
  1156.  
  1157. audioop: operations useful for audio programs, e.g. u-LAW and ADPCM
  1158. coding (dynamic only)
  1159.  
  1160. cd: interface to Indigo SCSI CDROM player audio library (sgi only)
  1161.  
  1162. jpeg: read files in JPEG format (dynamic only, sgi only; needs
  1163. external code)
  1164.  
  1165. imgfile: read SGI image files (dynamic only, sgi only)
  1166.  
  1167. sunaudiodev: interface to sun's /dev/audio (dynamic only, sun only)
  1168.  
  1169. sv: interface to Indigo video library (sgi only)
  1170.  
  1171. pc: a minimal set of MS-DOS interfaces (MS-DOS only)
  1172.  
  1173. rotor: encryption, by Lance Ellinghouse (dynamic only)
  1174.  
  1175.  
  1176. New standard modules
  1177. --------------------
  1178.  
  1179. Not all these modules are documented.  Read the source:
  1180. lib/<modulename>.py.  Sometimes a file lib/<modulename>.doc contains
  1181. additional documentation.
  1182.  
  1183. imghdr: recognizes image file headers
  1184.  
  1185. sndhdr: recognizes sound file headers
  1186.  
  1187. profile: print run-time statistics of Python code
  1188.  
  1189. readcd, cdplayer: companion modules for built-in module cd (sgi only)
  1190.  
  1191. emacs: interface to Emacs using py-connect.el (see below).
  1192.  
  1193. SOCKET: symbolic constant definitions for socket options
  1194.  
  1195. SUNAUDIODEV: symbolic constant definitions for sunaudiodef (sun only)
  1196.  
  1197. SV: symbolic constat definitions for sv (sgi only)
  1198.  
  1199. CD: symbolic constat definitions for cd (sgi only)
  1200.  
  1201.  
  1202. New demos
  1203. ---------
  1204.  
  1205. scripts/pp.py: execute Python as a filter with a Perl-like command
  1206. line interface
  1207.  
  1208. classes/: examples using the new class features
  1209.  
  1210. threads/: examples using the new thread module
  1211.  
  1212. sgi/cd/: examples using the new cd module
  1213.  
  1214.  
  1215. Changes to the documentation
  1216. ----------------------------
  1217.  
  1218. The last-minute syntax changes of release 0.9.6 are now reflected
  1219. everywhere in the manuals
  1220.  
  1221. The reference manual has a new section (3.2) on implementing new kinds
  1222. of numbers, sequences or mappings with user classes
  1223.  
  1224. Classes are now treated extensively in the tutorial (chapter 9)
  1225.  
  1226. Slightly restructured the system-dependent chapters of the library
  1227. manual
  1228.  
  1229. The file misc/EXTENDING incorporates documentation for mkvalue() and
  1230. a new section on error handling
  1231.  
  1232. The files misc/CLASSES and misc/ERRORS are no longer necessary
  1233.  
  1234. The doc/Makefile now creates PostScript files automatically
  1235.  
  1236.  
  1237. Miscellaneous changes
  1238. ---------------------
  1239.  
  1240. Incorporated Tim Peters' changes to python-mode.el, it's now version
  1241. 1.06
  1242.  
  1243. A python/Emacs bridge (provided by Terrence M. Brannon) lets a Python
  1244. program running in an Emacs buffer execute Emacs lisp code.  The
  1245. necessary Python code is in lib/emacs.py.  The Emacs code is
  1246. misc/py-connect.el (it needs some external Emacs lisp code)
  1247.  
  1248.  
  1249. Changes to the source code that affect C extension writers
  1250. ----------------------------------------------------------
  1251.  
  1252. New service function mkvalue() to construct a Python object from C
  1253. values according to a "format" string a la getargs()
  1254.  
  1255. Most functions from pythonmain.c moved to new pythonrun.c which is
  1256. in libpython.a.  This should make embedded versions of Python easier
  1257.  
  1258. ceval.h is split in eval.h (which needs compile.h and only declares
  1259. eval_code) and ceval.h (which doesn't need compile.hand declares the
  1260. rest)
  1261.  
  1262. ceval.h defines macros BGN_SAVE / END_SAVE for use with threads (to
  1263. improve the parallellism of multi-threaded programs by letting other
  1264. Python code run when a blocking system call or something similar is
  1265. made)
  1266.  
  1267. In structmember.[ch], new member types BYTE, CHAR and unsigned
  1268. variants have been added
  1269.  
  1270. New file xxmodule.c is a template for new extension modules.
  1271. 
  1272. 
  1273. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  1274.     id AA14861 (5.65b/3.6/CWI-Amsterdam); Tue, 12 Jan 1993 14:03:42 +0100
  1275. Received: by voorn.cwi.nl with SMTP
  1276.     id AA10677 (5.65b/3.5/CWI-Amsterdam); Tue, 12 Jan 1993 14:03:42 +0100
  1277. Message-Id: <9301121303.AA10677.guido@voorn.cwi.nl>
  1278. To: python-list@cwi.nl
  1279. Subject: Mac Python 0.9.8 ready
  1280. From: Guido.van.Rossum@cwi.nl
  1281. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1282. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1283. Date: Tue, 12 Jan 1993 14:03:41 +0100
  1284. Sender: Guido.van.Rossum@cwi.nl
  1285.  
  1286. To all ye Macintosh owners / Python lovers!
  1287.  
  1288. A Macintosh binary of a Python interpreter is now available.
  1289.  
  1290. Site            IP address         Directory
  1291.  
  1292. ftp.cwi.nl        192.16.184.180        /pub/python
  1293. wuarchive.wustl.edu    128.252.135.4        /pub
  1294.  
  1295. The filename is MacPython0.9.8.hqx.  This is a binhexed stuffit 1.5.1
  1296. archive of the application file only.  In order to get the Python
  1297. library (highly recommended :-) you still need to fetch and extract
  1298. the source distribution (python0.9.8.tar.Z) and copy python/lib/*.py
  1299. to your Macintosh.  The default search path is [':', ':lib', ':demo'].
  1300. The following built-in modules are present: sys, builtin, marshal,
  1301. struct, time, math, strop, time, mac, regex, stdwin, audioop, imageop,
  1302. rotor.
  1303.  
  1304. A new feature which isn't documented (yet): if a file PythonStartup
  1305. exists (in the current folder or in the system folder) it will be
  1306. executed when the interpreter is started interactively.
  1307.  
  1308. As in previous versions, if a TEXT file has owner PYTH (the same as
  1309. the Python application), opening it will launch the Python interpreter
  1310. and execute the file as a script.
  1311.  
  1312. And in case you wondered: the application's icon is supposed to
  1313. represent the 16-ton weight appearing in some Monty Python sketches :-)
  1314.  
  1315. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1316. 
  1317. 
  1318. Replied: Fri, 15 Jan 1993 22:59:47 +0100
  1319. Replied: python-list@cwi.nl
  1320. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  1321.     id AA07316 (5.65b/3.6/CWI-Amsterdam); Fri, 15 Jan 1993 20:45:56 +0100
  1322. From: Lance Ellinghouse <lance@markv.com>
  1323. X-Mailer: SCO System V Mail (version 3.2)
  1324. To: python-list@cwi.nl
  1325. Subject: marshall type but builds stringobj??
  1326. Date: Fri, 15 Jan 93 11:45:06 PST
  1327. Message-Id:  <9301151145.aa24928@hermix.markv.com>
  1328.  
  1329. Has anyone put together a 'marshall' type module that instead
  1330. of dumping everything to a file, it would create a stringobj that
  1331. contained the information???
  1332.  
  1333. I would like to be able to create a stringobj that contains the same
  1334. information as when you do a marshal.dump()... This will allow me
  1335. to send PYTHON objects across networks! :)
  1336.  
  1337. Lance Ellinghouse
  1338. lance@markv.com
  1339. 
  1340. 
  1341. Replied: Fri, 15 Jan 1993 22:55:59 +0100
  1342. Replied: postmaster@isye.gatech.edu
  1343. Received: by charon.cwi.nl 
  1344.     id AA07318 (5.65b/3.6/CWI-Amsterdam); Fri, 15 Jan 1993 20:45:56 +0100
  1345. Date: Fri, 15 Jan 1993 20:45:56 +0100
  1346. From: MAILER-DAEMON@cwi.nl
  1347. Subject: Returned mail: Deferred: Host Name Lookup Failure
  1348. Message-Id: <9301151945.AA07318.MAILER-DAEMON@charon.cwi.nl>
  1349. To: owner-python-list@cwi.nl
  1350.  
  1351.    ----- Transcript of session follows -----
  1352. While talking to isye.gatech.edu:
  1353. >>> RCPT To:<mondomon@isye.gatech.edu>
  1354. <<< 550 <mondomon@isye.gatech.edu>... User unknown
  1355. 550 "Allan Stuart Mackinnon Jr." <mondomon@isye.gatech.edu>... User unknown
  1356.  
  1357.    ----- Unsent message follows -----
  1358. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  1359.     id AA07316 (5.65b/3.6/CWI-Amsterdam); Fri, 15 Jan 1993 20:45:56 +0100
  1360. From: Lance Ellinghouse <lance@markv.com>
  1361. X-Mailer: SCO System V Mail (version 3.2)
  1362. To: python-list@cwi.nl
  1363. Subject: marshall type but builds stringobj??
  1364. Date: Fri, 15 Jan 93 11:45:06 PST
  1365. Message-Id:  <9301151145.aa24928@hermix.markv.com>
  1366.  
  1367. Has anyone put together a 'marshall' type module that instead
  1368. of dumping everything to a file, it would create a stringobj that
  1369. contained the information???
  1370.  
  1371. I would like to be able to create a stringobj that contains the same
  1372. information as when you do a marshal.dump()... This will allow me
  1373. to send PYTHON objects across networks! :)
  1374.  
  1375. Lance Ellinghouse
  1376. lance@markv.com
  1377. 
  1378. 
  1379. To: postmaster@isye.gatech.edu
  1380. Subject: What happened to Allan Stuart Mackinnon Jr. <mondomon@isye.gatech.edu>
  1381. In-reply-to: Your message of "Fri, 15 Jan 1993 20:45:56 MET."
  1382.              <9301151945.AA07318.MAILER-DAEMON@charon.cwi.nl> 
  1383. From: Guido.van.Rossum@cwi.nl
  1384. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1385. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1386. Date: Fri, 15 Jan 1993 22:55:57 +0100
  1387. Sender: guido
  1388.  
  1389. Hello,
  1390.  
  1391. I'm maintaining a mailing list which contains the address
  1392.  
  1393.     "Allan Stuart Mackinnon Jr." <mondomon@isye.gatech.edu>
  1394.  
  1395. The latest mail to this address fails (see below).  What has happened?
  1396. Is there a new address, or should I just remove the address from my
  1397. mailing list?
  1398.  
  1399. Thank you for your time,
  1400.  
  1401. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1402.  
  1403.  
  1404. >   ----- Transcript of session follows -----
  1405. >While talking to isye.gatech.edu:
  1406. >>>> RCPT To:<mondomon@isye.gatech.edu>
  1407. ><<< 550 <mondomon@isye.gatech.edu>... User unknown
  1408. >550 "Allan Stuart Mackinnon Jr." <mondomon@isye.gatech.edu>... User unknown
  1409. >
  1410. >   ----- Unsent message follows -----
  1411. >Received: from hermix.markv.com by charon.cwi.nl with SMTP
  1412. >    id AA07316 (5.65b/3.6/CWI-Amsterdam); Fri, 15 Jan 1993 20:45:56 +0100
  1413. >From: Lance Ellinghouse <lance@markv.com>
  1414. >X-Mailer: SCO System V Mail (version 3.2)
  1415. >To: python-list@cwi.nl
  1416. >Subject: marshall type but builds stringobj??
  1417. >Date: Fri, 15 Jan 93 11:45:06 PST
  1418. >Message-Id:  <9301151145.aa24928@hermix.markv.com>
  1419. >
  1420. >Has anyone put together a 'marshall' type module that instead
  1421. >of dumping everything to a file, it would create a stringobj that
  1422. >contained the information???
  1423. >
  1424. >I would like to be able to create a stringobj that contains the same
  1425. >information as when you do a marshal.dump()... This will allow me
  1426. >to send PYTHON objects across networks! :)
  1427. >
  1428. >Lance Ellinghouse
  1429. >lance@markv.com
  1430.  
  1431. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1432. 
  1433. 
  1434. To: python-list@cwi.nl
  1435. Subject: Re: marshall type but builds stringobj?? 
  1436. In-reply-to: Your message of "Fri, 15 Jan 1993 11:45:06 MET."
  1437.              <9301151145.aa24928@hermix.markv.com> 
  1438. From: Guido.van.Rossum@cwi.nl
  1439. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1440. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1441. Date: Fri, 15 Jan 1993 22:59:46 +0100
  1442. Sender: guido
  1443.  
  1444. Lance Ellinghouse:
  1445.  
  1446. >Has anyone put together a 'marshall' type module that instead
  1447. >of dumping everything to a file, it would create a stringobj that
  1448. >contained the information???
  1449. >
  1450. >I would like to be able to create a stringobj that contains the same
  1451. >information as when you do a marshal.dump()... This will allow me
  1452. >to send PYTHON objects across networks! :)
  1453.  
  1454. You can already send Python objects as strings across networks using
  1455. repr() or `` and eval(), but you're right that marshal would be more
  1456. efficient.  (Though not more general -- the same objects for which
  1457. eval(`x`) fails also cannot be load()ed by marshal.)
  1458.  
  1459. This has been asked so many times now that I think I'll try to do
  1460. something about it...
  1461.  
  1462. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1463. 
  1464. 
  1465. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  1466.     id AA12164 (5.65b/3.6/CWI-Amsterdam); Fri, 15 Jan 1993 22:59:47 +0100
  1467. Received: by voorn.cwi.nl with SMTP
  1468.     id AA21221 (5.65b/3.5/CWI-Amsterdam); Fri, 15 Jan 1993 22:59:47 +0100
  1469. Message-Id: <9301152159.AA21221.guido@voorn.cwi.nl>
  1470. To: python-list@cwi.nl
  1471. Subject: Re: marshall type but builds stringobj?? 
  1472. In-Reply-To: Your message of "Fri, 15 Jan 1993 11:45:06 MET."
  1473.              <9301151145.aa24928@hermix.markv.com> 
  1474. From: Guido.van.Rossum@cwi.nl
  1475. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1476. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1477. Date: Fri, 15 Jan 1993 22:59:46 +0100
  1478. Sender: Guido.van.Rossum@cwi.nl
  1479.  
  1480. Lance Ellinghouse:
  1481.  
  1482. >Has anyone put together a 'marshall' type module that instead
  1483. >of dumping everything to a file, it would create a stringobj that
  1484. >contained the information???
  1485. >
  1486. >I would like to be able to create a stringobj that contains the same
  1487. >information as when you do a marshal.dump()... This will allow me
  1488. >to send PYTHON objects across networks! :)
  1489.  
  1490. You can already send Python objects as strings across networks using
  1491. repr() or `` and eval(), but you're right that marshal would be more
  1492. efficient.  (Though not more general -- the same objects for which
  1493. eval(`x`) fails also cannot be load()ed by marshal.)
  1494.  
  1495. This has been asked so many times now that I think I'll try to do
  1496. something about it...
  1497.  
  1498. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1499. 
  1500. 
  1501. Replied: Sat, 16 Jan 1993 00:29:00 +0100
  1502. Replied: python-list@cwi.nl
  1503. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  1504.     id AA16966 (5.65b/3.6/CWI-Amsterdam); Sat, 16 Jan 1993 00:15:24 +0100
  1505. From: Lance Ellinghouse <lance@markv.com>
  1506. X-Mailer: SCO System V Mail (version 3.2)
  1507. To: python-list@cwi.nl
  1508. Subject: Re: marshall type but builds stringobj??
  1509. Date: Fri, 15 Jan 93 15:15:06 PST
  1510. Message-Id:  <9301151515.aa13003@hermix.markv.com>
  1511.  
  1512. In-Reply-To: Your message of "Fri, 15 Jan 1993 11:45:06 MET."
  1513.              <9301151145.aa24928@hermix.markv.com> 
  1514. From: Guido.van.Rossum@cwi.nl
  1515. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1516. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1517. Date: Fri, 15 Jan 1993 22:59:46 +0100
  1518. Sender: Guido.van.Rossum@cwi.nl
  1519. Status: R
  1520.  
  1521. Guido:
  1522. >Lance Ellinghouse:
  1523. >>Has anyone put together a 'marshall' type module that instead
  1524. >>of dumping everything to a file, it would create a stringobj that
  1525. >>contained the information???
  1526. >>
  1527. >>I would like to be able to create a stringobj that contains the same
  1528. >>information as when you do a marshal.dump()... This will allow me
  1529. >>to send PYTHON objects across networks! :)
  1530. > You can already send Python objects as strings across networks using
  1531. > repr() or `` and eval(), but you're right that marshal would be more
  1532. > efficient.  (Though not more general -- the same objects for which
  1533. > eval(`x`) fails also cannot be load()ed by marshal.)
  1534.  
  1535. This may be true, but You cannot send the following easily using repr()
  1536. or `` or eval():
  1537.  
  1538.     (0,'This is a test',func)
  1539.  
  1540. Where func is a code object that should be sent and executed on the
  1541. remote machine (where 'func' did NOT exist on the remote machine).
  1542.  
  1543. > This has been asked so many times now that I think I'll try to do
  1544. > something about it...
  1545.  
  1546. Great!
  1547.  
  1548. Lance Ellinghouse
  1549. lance@markv.com
  1550.  
  1551. 
  1552. 
  1553. To: python-list@cwi.nl
  1554. Subject: Re: marshall type but builds stringobj?? 
  1555. In-reply-to: Your message of "Fri, 15 Jan 1993 15:15:06 MET."
  1556.              <9301151515.aa13003@hermix.markv.com> 
  1557. From: Guido.van.Rossum@cwi.nl
  1558. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1559. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1560. Date: Sat, 16 Jan 1993 00:28:52 +0100
  1561. Sender: guido
  1562.  
  1563. me:
  1564. >> You can already send Python objects as strings across networks using
  1565. >> repr() or `` and eval(), but you're right that marshal would be more
  1566. >> efficient.  (Though not more general -- the same objects for which
  1567. >> eval(`x`) fails also cannot be load()ed by marshal.)
  1568.  
  1569. Lance:
  1570. >This may be true, but You cannot send the following easily using repr()
  1571. >or `` or eval():
  1572. >
  1573. >    (0,'This is a test',func)
  1574. >
  1575. >Where func is a code object that should be sent and executed on the
  1576. >remote machine (where 'func' did NOT exist on the remote machine).
  1577.  
  1578. And indeed you can't marshal function objects either.  The reason is
  1579. that a function object contains a reference to the module in which it
  1580. is declared, because it *may* need global variables there.  The same
  1581. module may not exist at the remote end, and even if it exists the
  1582. effect would not be the same, since the values of the global variables
  1583. in that module may differ.  This is not likely to change.  Note that
  1584. even if the function *doesn't* reference global variables it still
  1585. contains a pointer to the module, since the parser isn't powerful
  1586. enough to detect this.
  1587.  
  1588. If you really need to pass a function to a remote machine, you are
  1589. better off sending the function's source code.
  1590.  
  1591. "Code objects", the internal "compiled" form of Python code, can be
  1592. marshalled, however there is no way to call a code object (the
  1593. implementation of "import" uses code objects).  (Maybe there should be
  1594. a way?)
  1595.  
  1596. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1597.  
  1598. 
  1599. 
  1600. Received: from dahlia.cwi.nl by charon.cwi.nl with SMTP
  1601.     id AA19458 (5.65b/3.6/CWI-Amsterdam); Sat, 16 Jan 1993 00:28:54 +0100
  1602. Received: by dahlia.cwi.nl with SMTP
  1603.     id AA09693 (5.65b/3.5/CWI-Amsterdam); Sat, 16 Jan 1993 00:28:53 +0100
  1604. Message-Id: <9301152328.AA09693.guido@dahlia.cwi.nl>
  1605. To: python-list@cwi.nl
  1606. Subject: Re: marshall type but builds stringobj?? 
  1607. In-Reply-To: Your message of "Fri, 15 Jan 1993 15:15:06 MET."
  1608.              <9301151515.aa13003@hermix.markv.com> 
  1609. From: Guido.van.Rossum@cwi.nl
  1610. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1611. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1612. Date: Sat, 16 Jan 1993 00:28:52 +0100
  1613. Sender: Guido.van.Rossum@cwi.nl
  1614.  
  1615. me:
  1616. >> You can already send Python objects as strings across networks using
  1617. >> repr() or `` and eval(), but you're right that marshal would be more
  1618. >> efficient.  (Though not more general -- the same objects for which
  1619. >> eval(`x`) fails also cannot be load()ed by marshal.)
  1620.  
  1621. Lance:
  1622. >This may be true, but You cannot send the following easily using repr()
  1623. >or `` or eval():
  1624. >
  1625. >    (0,'This is a test',func)
  1626. >
  1627. >Where func is a code object that should be sent and executed on the
  1628. >remote machine (where 'func' did NOT exist on the remote machine).
  1629.  
  1630. And indeed you can't marshal function objects either.  The reason is
  1631. that a function object contains a reference to the module in which it
  1632. is declared, because it *may* need global variables there.  The same
  1633. module may not exist at the remote end, and even if it exists the
  1634. effect would not be the same, since the values of the global variables
  1635. in that module may differ.  This is not likely to change.  Note that
  1636. even if the function *doesn't* reference global variables it still
  1637. contains a pointer to the module, since the parser isn't powerful
  1638. enough to detect this.
  1639.  
  1640. If you really need to pass a function to a remote machine, you are
  1641. better off sending the function's source code.
  1642.  
  1643. "Code objects", the internal "compiled" form of Python code, can be
  1644. marshalled, however there is no way to call a code object (the
  1645. implementation of "import" uses code objects).  (Maybe there should be
  1646. a way?)
  1647.  
  1648. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1649.  
  1650. 
  1651. 
  1652. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  1653.     id AA23827 (5.65b/3.6/CWI-Amsterdam); Mon, 18 Jan 1993 10:53:50 +0100
  1654. Received: by voorn.cwi.nl with SMTP
  1655.     id AA25242 (5.65b/3.5/CWI-Amsterdam); Mon, 18 Jan 1993 10:53:50 +0100
  1656. Message-Id: <9301180953.AA25242.guido@voorn.cwi.nl>
  1657. To: python-list@cwi.nl
  1658. Subject: bugfix for longobject.c (all versions)
  1659. From: Guido.van.Rossum@cwi.nl
  1660. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  1661. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  1662. Date: Mon, 18 Jan 1993 10:53:49 +0100
  1663. Sender: Guido.van.Rossum@cwi.nl
  1664.  
  1665. I've been told that there's a bug in the comparison of negative long
  1666. integers.  It's a record-breaking bug, since it has existed since the
  1667. very first implementation of long ints!  So maybe it isn't of critical
  1668. importance, but since I've just found a 2-line fix I don't want to
  1669. withhold that from y'all.
  1670.  
  1671. You don't need to test whether you have the bug -- I'm sure you have
  1672. it, but in case you're interested, it turns out that -2L compares
  1673. greater than -1L ...  Apply this patch to longobject and it's fixed...
  1674. (Not that you care -- or else why did nobody complain before?)
  1675.  
  1676. ===================================================================
  1677. RCS file: /ufs/guido/CVSROOT/python/src/longobject.c,v
  1678. retrieving revision 1.17
  1679. diff -c -1 -r1.17 longobject.c
  1680. *** 1.17    1992/09/17 17:54:47
  1681. --- longobject.c    1993/01/18 09:16:05
  1682. ***************
  1683. *** 608,611 ****
  1684.               sign = 0;
  1685. !         else
  1686.               sign = (int)a->ob_digit[i] - (int)b->ob_digit[i];
  1687.       }
  1688. --- 608,614 ----
  1689.               sign = 0;
  1690. !         else {
  1691.               sign = (int)a->ob_digit[i] - (int)b->ob_digit[i];
  1692. +             if (a->ob_size < 0)
  1693. +                 sign = -sign;
  1694. +         }
  1695.       }
  1696. ===================================================================
  1697.  
  1698. Note that this doesn't mean I'll soon bring out a new release -- 0.9.8
  1699. appears quite stable, there have been a number of problem reports but
  1700. these all pertain to minor things that can be fixed by massaging the
  1701. Makefile a little bit, or they are very platform-specific (hallo Jaap!).
  1702.  
  1703. Cheers,
  1704.  
  1705. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  1706. 
  1707. 
  1708. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  1709.     id AA29971 (5.65b/3.8/CWI-Amsterdam); Fri, 22 Jan 1993 00:32:41 +0100
  1710. Received: by voorn.cwi.nl with SMTP
  1711.     id AA06986 (5.65b/3.8/CWI-Amsterdam); Fri, 22 Jan 1993 00:32:40 +0100
  1712. Message-Id: <9301212332.AA06986=guido@voorn.cwi.nl>
  1713. To: python-list@cwi.nl
  1714. Subject: How about an ARRAY type in Python
  1715. From: se@risc3.mi.Uni-Koeln.DE (Stefan Esser)
  1716. Date: Fri, 22 Jan 1993 00:32:40 +0100
  1717. Sender: Guido.van.Rossum@cwi.nl
  1718.  
  1719. [Posting for Stefan Esser who is having trouble with mailing to the
  1720. list.  Anyone else have a complaint about the list recently?  --Guido]
  1721.  
  1722. Hi everybody !
  1723.  
  1724.  
  1725. Having been a long time user of Perl, I've given the just announced
  1726. Python 0.9.8 a try and was surprised of the clean design and easy 
  1727. expandabilty of the language.
  1728.  
  1729. But there is one thing that I'd like to see changed for performance
  1730. reasons, and that is the fact, that the only array type supported is
  1731. the array of characters (that is strings).
  1732.  
  1733. I'm new to this list, so I don't know if there has been much discussion 
  1734. on that topic and what the results (if any) have been...
  1735.  
  1736.  
  1737. Although the Python interpreter isn't fast compared to compiled languages,
  1738. I'd like to use Python for a purpose where Megabytes of data have to be 
  1739. processed: the examination of nuclear physics spectroscopy data.
  1740.  
  1741. There is a library I've written some time ago, which performs conversion
  1742. and compression of our experimental data, but it has proven to be an 
  1743. annoying task to combine these access functions into useable programs 
  1744. performing tasks like matrix transpose or projections with typical 
  1745. matrix sizes of 4096*4096 elements.
  1746.  
  1747. Python makes it (due to its exception concept) very easy to write programs 
  1748. with reasonable behavior in the case of runtime or operator errors, 
  1749. and catching exceptions in a user friendly way is the main reason for my 
  1750. C programs' complexity now.
  1751.  
  1752.  
  1753. Now what I'd like to be able to do in Python:
  1754.  
  1755. 1) Open existing matrix files in any of the supported formats
  1756.    (little/big endian 2/4 byte integer, floats, text, compressed,...)
  1757.    and getting information on file type and matrix dimensions
  1758.    [ got that already to work fine ... ]
  1759.  
  1760.  
  1761. 2) Access data from these files using the slice syntax of Python.
  1762.    [ Quite simple if I'm going to unpack the arrays, the low level 
  1763.      routines operate on, into lists. But reading a typical matrix file 
  1764.      once would then mean unpacking 64 Mbyte of data into 16Mio int objects.
  1765.      And that's why I (think that I) need an array object class. ]
  1766.  
  1767.  
  1768. 3) Assign a 1-dim array (or a 1-dim slice of a 2-dim array) to a line or 
  1769.    column of a 2-dim array.
  1770.    This ought to make it possible to write a matrix transpose this way:
  1771.  
  1772.     for i in range(src.lines):
  1773.         dst[i][:] = src[:][i]
  1774.  
  1775.    The semantics of that operation have to be quite different from what 
  1776.    they are on lists now!
  1777.    (Eg. src[:][i] is equivalent to src[i] now, if src is a list.)
  1778.    This may require changes to the interpreter to work (I'm not sure 
  1779.    whether it can be easily implemented by __getitem__/__getslice__ and 
  1780.    corresponding __setXX__ methods ? If array_ass_slice() can be made to do 
  1781.    the right thing, then there was no need for any change to python ??).
  1782.  
  1783.  
  1784. 4) Make this work not only on my special matrix file objects, but also on 
  1785.    a general Python object that represents an array in RAM by indexing 
  1786.    into a contigous large array, instead of as a list/tree structure.
  1787.    The special object of 3) can now be made a special case of this more 
  1788.    general object.
  1789.  
  1790.  
  1791. 5) Have a way to create array object instances, eg. using the following syntax:
  1792.  
  1793.     a = 0[10]    # 1-dim array of 10 integers, initialized to 0
  1794.     f = 1.0[10][20] # 2-dim array of 10 lines of 20 floats each, init=1.0
  1795.     o = None[10]    # 1-dim array of 10 objects, initialized to <None>
  1796.     s = ' '[100]    # 100 byte string initialized to blank space
  1797.     s = ''[100]    # ... special case: as above, but init to '\0'
  1798.  
  1799.  
  1800.  
  1801. This array object ought (IMHO) to be represented by the following C struct:
  1802.  
  1803. typedef struct {
  1804.     int        mult;        /* horner scheme multiplicator             */
  1805.     int        limit;        /* index range is [0 .. (limit-1)]         */
  1806. }
  1807.  
  1808. typedef struct {
  1809.     OB_HEAD
  1810.     void    *data;
  1811.     char    elemtype;    /* elem_char, elem_int, elem_float, elem_obj */
  1812.     char    status;        /* controls behaviour of slicing and assign. */
  1813.     int        dims;        /* 0 = scalar, 1 = vector, 2 = matrix, ...   */
  1814.     dim_type    dim[1];        /* actually repeated 'dims' times ...         */
  1815. } arrayobject;
  1816.  
  1817.  
  1818.  
  1819. A 2-dim array A of 10 lines of 20 columns of integers might then be 
  1820. represented by the following actual data:
  1821.  
  1822.     data     = <array base>
  1823.     elemtype     = elem_int
  1824.     status     = ( to be specified :)
  1825.     dims     = 2
  1826.     dim[0].mult  = 4    /* sizeof(int) */
  1827.     dim[0].limit = 20
  1828.     dim[1].mult  = 20
  1829.     dim[1].limit = 10
  1830.  
  1831. Slice and index operations only modify (a copy) of struct arrayobject,
  1832. eg. A[0:2][0:4] would correspond to the same data array, but the following 
  1833. descriptor:
  1834.  
  1835.     data     = <array base>
  1836.     elemtype     = elem_int
  1837.     status     = ( to be specified :)
  1838.     dims     = 2
  1839.     dim[0].mult  = 4    /* sizeof(int) */
  1840.     dim[0].limit = 4
  1841.     dim[1].mult  = 20
  1842.     dim[1].limit = 2
  1843.  
  1844. A[1:3][2:6] would be identical, except that the data pointer would have 
  1845. been adjusted to point to the address of A[1][2] instead of to the base 
  1846. of the array.
  1847.  
  1848.     data     = <array base> + (( 1 ) * dim[1].mult + 2) * dim[0].mult
  1849.          = <array base> + 88
  1850.     elemtype     = elem_int
  1851.     ...
  1852.  
  1853.  
  1854.  
  1855. Further ideas on array object semantics:
  1856.  
  1857. (This is what I need in my applications, it isn't neccessarily what the
  1858.  way one would like an general array object to behave. That's the reason
  1859.  I want to discuss this array object type ...)
  1860.  
  1861. Assignment compatibility requires same number of (free) dimensions and 
  1862. same index range in each dimension. Each index (as opposed to slice) 
  1863. operator reduces the dimension of the resulting object by one. 
  1864.  
  1865. Given 3-dim arrays A,B of 10*20*30 elements (that is 30 per 'line'):
  1866.  
  1867. High dimension slices containing the full range of indizes can be 
  1868. omitted: A[0] is interpreted as A[:][:][0] in the case of a 3-dim array.
  1869.  
  1870.  
  1871. Assignment compatibility:
  1872.  
  1873.     B[:] = A[0:10][0:20][0:30]    # same index ranges on both sides
  1874.     B[:] = A[:]            # same as above in this particular case
  1875.  
  1876.     B[0:20][0] = A[0][0:20]        # both got one index fixed and 20 
  1877.                     # elements at the lowest non fixed 
  1878.                     # index
  1879.  
  1880.     B[0:2][0][0:2] = A[0][0:2][0:2] # same as above, except different 
  1881.                     # number of elements
  1882.  
  1883.     A[0][0:2][0:2] = ((1,2),(3,4))    # assignment between arrays and lists
  1884.                     # ought to work in both directions
  1885.  
  1886.  
  1887. Methods of array instances:
  1888.  
  1889.     A.__min__()    min(A[0:3])    # element with min. value
  1890.     A.__max__()    max(A{:])    # element with max. value
  1891.     A.__len__()    len(A[:])    # number of elements
  1892.     A.__sum__()    A[:] + B[:]    # add two matrizes
  1893.     A.__mult__()    A[:] * n    # mult each elem with scalar 
  1894.     A.__mult__()    A[:] * B[:}    # scalar product
  1895.     ...
  1896.  
  1897.  
  1898. Attributes:
  1899.  
  1900.     A.dims                # RO dimensions
  1901.     A.dim                # list of limits, 
  1902.                     # highest dim first (or last ??)
  1903. ???    A.elemtype            # type object corresp. to elements
  1904.  
  1905.  
  1906. One think I'm considering useful is, to treat (given the above definition of 
  1907. array A) 
  1908.  
  1909.     A[0]    equiv. A[0][0][0],
  1910. but     A[0:1]    equiv. A[:][:][0:1] equiv A[:][:][0]
  1911.  
  1912. This would make access to the undelying element object easy without need
  1913. to have an index expression corresponding to the dimension of the array.
  1914.  
  1915. (Else in case of a 4-dim array A:  A[0][0][0] equiv. A[:][0][0][0] ...
  1916.  ... that is: an 1-dim array as opposed to the element type (eg. integer) 
  1917.  in case of 'A' being a 3-dim array, given the above index expression).
  1918.  
  1919. (A flag, whether there has at least one slice op. [:] been applied to the 
  1920.  array, ought to be held in the '.status' element of the arrayobject struct. 
  1921.  Or perhaps the number of slice ops done ought to be kept in that field ...)
  1922.  
  1923.  
  1924. Hmm, that's enough for the moment I think (anybody still reading this ???).
  1925. Hope this wasn't to obfuscated (my thoughts and my english, that is ...).
  1926.  
  1927.  
  1928. Are their any design problems with my proposed array type ?
  1929.  
  1930. Anything to consider, to make it fit better into the Python frame ?
  1931.  
  1932. Is it impossible to do, what I'm trying to, because of language 
  1933. limitations or design decisions in the Python compiler/interpreter ?
  1934.  
  1935.  
  1936. Any ideas ???
  1937.  
  1938.  
  1939. Thanks in advance,
  1940.  
  1941. STefan
  1942. --
  1943.  Stefan Esser,  Institute of Nuclear Physics,  University of Cologne,  Germany
  1944.  se@IKP.Uni-Koeln.DE                                           [134.95.192.50]
  1945.  se@MI.Uni-Koeln.DE                                            [134.95.208.16]
  1946.  
  1947. 
  1948. 
  1949. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  1950.     id AA17735 (5.65b/3.8/CWI-Amsterdam); Wed, 27 Jan 1993 03:16:28 +0100
  1951. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  1952.     id AA00718; Tue, 26 Jan 1993 21:12:57 -0500
  1953. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  1954.     id AA16200; Tue, 26 Jan 93 21:18:27 EST
  1955. Received: by kaos.ksr.com (4.0/KSR-2.0)
  1956.     id AA16665; Tue, 26 Jan 93 21:18:26 EST
  1957. Message-Id: <9301270218.AA16665@kaos.ksr.com>
  1958. To: Jaap Vermeulen <jaap@sequent.com>
  1959. Subject: Re: passing variable length arguments without unpacking them
  1960. Cc: python-list@cwi.nl
  1961. Date: Tue, 26 Jan 93 21:18:25 EST
  1962. From: Tim Peters <tim@ksr.com>
  1963.  
  1964. > I'm using python 0.9.8 and try to use the variable length arguments
  1965. > ...
  1966. > I cannot arbitrarily pass along a set of arguments without interpreting
  1967. > them.  For example (albeit articifial):
  1968. >
  1969. > count = 10
  1970. > def recurse(*args):
  1971. >     global count
  1972. >     count = count - 1
  1973. >     if (count == 0): one, two, three = args
  1974. >     else: recurse(args)
  1975. >
  1976. > recurse(1, 2, 3)
  1977. >
  1978. > This will fail. ...
  1979.  
  1980. Let me stick in a print so it's easier to see why it fails:
  1981.  
  1982. count = 10
  1983. def recurse(*args):
  1984.     global count
  1985.     print 'Entering recurse, count =', count, 'args =', args
  1986.     count = count - 1
  1987.     if (count == 0): one, two, three = args
  1988.     else: recurse(args)
  1989.  
  1990. This yields:
  1991.  
  1992. >>> recurse(1,2,3)
  1993. Entering recurse, count = 10 args = (1, 2, 3)
  1994. Entering recurse, count = 9 args = ((1, 2, 3),)
  1995. Entering recurse, count = 8 args = (((1, 2, 3),),)
  1996. Entering recurse, count = 7 args = ((((1, 2, 3),),),)
  1997. Entering recurse, count = 6 args = (((((1, 2, 3),),),),)
  1998. Entering recurse, count = 5 args = ((((((1, 2, 3),),),),),)
  1999. Entering recurse, count = 4 args = (((((((1, 2, 3),),),),),),)
  2000. Entering recurse, count = 3 args = ((((((((1, 2, 3),),),),),),),)
  2001. Entering recurse, count = 2 args = (((((((((1, 2, 3),),),),),),),),)
  2002. Entering recurse, count = 1 args = ((((((((((1, 2, 3),),),),),),),),),)
  2003. ValueError: unpack tuple of wrong size
  2004. Stack backtrace (innermost last):
  2005.   File "<stdin>", line 1
  2006.   File "./temp.py", line 7
  2007.     else: recurse(args)
  2008.   File "./temp.py", line 7
  2009.     else: recurse(args)
  2010.   File "./temp.py", line 7
  2011.     else: recurse(args)
  2012.   File "./temp.py", line 7
  2013.     else: recurse(args)
  2014.   File "./temp.py", line 7
  2015.     else: recurse(args)
  2016.   File "./temp.py", line 7
  2017.     else: recurse(args)
  2018.   File "./temp.py", line 7
  2019.     else: recurse(args)
  2020.   File "./temp.py", line 7
  2021.     else: recurse(args)
  2022.   File "./temp.py", line 7
  2023.     else: recurse(args)
  2024.   File "./temp.py", line 6
  2025.     if (count == 0): one, two, three = args
  2026. >>>
  2027.  
  2028. I understand that this isn't what you want, but the rule does seem clear
  2029. & consistent:  a "*" formal argument sees a tuple comprising the actual
  2030. arguments.  The behavior of recurse is at least predictable given that.
  2031. And at least I find it very natural <grin>.
  2032.  
  2033. Your problem is that, in trying to pass the argument list on, you're
  2034. actually passing a tuple instead of the original argument list.  The
  2035. built-in function "apply" goes the other direction, making a tuple act as
  2036. if it were an argument list.  This solves the problem nicely:
  2037.  
  2038. count = 10
  2039. def rec2(*args):
  2040.     global count
  2041.     print 'Entering rec2, count =', count, 'args =', args
  2042.     count = count - 1
  2043.     if (count == 0): one, two, three = args
  2044.     else: apply(rec2,args)    # only line that's substantially different
  2045.  
  2046. This yields:
  2047. >>> rec2(1,2,3)
  2048. Entering rec2, count = 10 args = (1, 2, 3)
  2049. Entering rec2, count = 9 args = (1, 2, 3)
  2050. Entering rec2, count = 8 args = (1, 2, 3)
  2051. Entering rec2, count = 7 args = (1, 2, 3)
  2052. Entering rec2, count = 6 args = (1, 2, 3)
  2053. Entering rec2, count = 5 args = (1, 2, 3)
  2054. Entering rec2, count = 4 args = (1, 2, 3)
  2055. Entering rec2, count = 3 args = (1, 2, 3)
  2056. Entering rec2, count = 2 args = (1, 2, 3)
  2057. Entering rec2, count = 1 args = (1, 2, 3)
  2058. >>>
  2059.  
  2060. > In reality I'm using this in class initialization routines, where I try
  2061. > to do something like: [a reasonable thing to want to do deleted] ...
  2062.  
  2063. I confess I didn't try it, but I _believe_ the same technique will solve
  2064. your subclass/subsubclass/etc problems.
  2065.  
  2066. > ...
  2067. > Any solutions to these problems?
  2068.  
  2069. hoping-that-did-the-trick-for-you!-ly y'rs  - tim
  2070.  
  2071. Tim Peters   tim@ksr.com
  2072. not speaking for Kendall Square Research Corp
  2073. 
  2074. 
  2075. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  2076.     id AA18230 (5.65b/3.8/CWI-Amsterdam); Wed, 27 Jan 1993 03:34:37 +0100
  2077. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  2078.     id AA03270; Tue, 26 Jan 93 18:35:21 -0800
  2079. Received: by eng2.sequent.com (5.65/1.34)
  2080.     id AA20963; Tue, 26 Jan 93 18:34:27 -0800
  2081. Message-Id: <9301270234.AA20963@eng2.sequent.com>
  2082. To: Tim Peters <tim@ksr.com>
  2083. Cc: python-list@cwi.nl
  2084. Subject: Re: passing variable length arguments without unpacking them 
  2085. Priority: Normal
  2086. Precedence: first-class
  2087. Organization: Sequent Computer Systems, Inc.
  2088.               Service Technology - MailStop: RHE2-758
  2089.           15450 S.W. Koll Parkway
  2090.               Beaverton, OR  97006
  2091. X-Phone: (503) 578-4404
  2092. X-Fax: (503) 578-7569
  2093. X-Uucp: ...!uunet!sequent!jaap
  2094. X-Internet: jaap@sequent.com
  2095. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  2096.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  2097.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  2098. In-Reply-To: Tim Peters's message of Tue, 26 Jan 1993 21:18:25 -0500.
  2099.              <9301270218.AA16665@kaos.ksr.com> 
  2100. Date: Tue, 26 Jan 1993 18:34:26 -0800
  2101. From: Jaap Vermeulen <jaap@sequent.com>
  2102.  
  2103.  
  2104. | Your problem is that, in trying to pass the argument list on, you're
  2105. | actually passing a tuple instead of the original argument list.  The
  2106. | built-in function "apply" goes the other direction, making a tuple act as
  2107. | if it were an argument list.  This solves the problem nicely:
  2108.  
  2109. I knew I was overlooking something.  Thanks for the solution.  I
  2110. remembered vaguely that I read something about it in the manuals, but
  2111. wasn't willing to reread everything to find it.  HINT FOR GUIDO:  I did
  2112. read the sections about functions in the reference manual and I don't
  2113. think it referred to apply() whatsoever (it *did* talk about variable
  2114. argument lists).
  2115.  
  2116. I was thrown off by the non-intuitive fact that a tuple *will* get
  2117. unpacked when assigned to formal arguments directly, i.e.:
  2118.  
  2119. >>> def fun1(arg1, arg2):
  2120. ...    pass
  2121. ...
  2122. >>> fun1((1, 2))
  2123. >>>
  2124.  
  2125. works like a champ.  I guess this is for backwards compatibility.
  2126.  
  2127. Thanks again,
  2128.  
  2129.     -Jaap-
  2130. --
  2131. Jaap Vermeulen                    +--------------------------+
  2132.                         | Sequent Computer Systems |
  2133.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  2134.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  2135. 
  2136. 
  2137. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  2138.     id AA19008 (5.65b/3.8/CWI-Amsterdam); Wed, 27 Jan 1993 04:34:05 +0100
  2139. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  2140.     id AA00835; Tue, 26 Jan 1993 22:30:50 -0500
  2141. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  2142.     id AA17298; Tue, 26 Jan 93 22:36:20 EST
  2143. Received: by kaos.ksr.com (4.0/KSR-2.0)
  2144.     id AA17468; Tue, 26 Jan 93 22:36:19 EST
  2145. Message-Id: <9301270336.AA17468@kaos.ksr.com>
  2146. To: Jaap Vermeulen <jaap@sequent.com>
  2147. Subject: Re: passing variable length arguments without unpacking them
  2148. Cc: python-list@cwi.nl
  2149. Date: Tue, 26 Jan 93 22:36:19 EST
  2150. From: Tim Peters <tim@ksr.com>
  2151.  
  2152. You're welcome, Jaap!  I'm happy if it solved your problem.
  2153.  
  2154. > ...
  2155. > I was thrown off by the non-intuitive fact that a tuple *will* get
  2156. > unpacked when assigned to formal arguments directly, i.e.:
  2157. >
  2158. > >>> def fun1(arg1, arg2):
  2159. > ...    pass
  2160. > ...
  2161. > >>> fun1((1, 2))
  2162. > >>>
  2163. >
  2164. > works like a champ.  I guess this is for backwards compatibility.
  2165.  
  2166. Speaking of remembering you've seen something but can't quite recall
  2167. where, I just found this (again) in python-NEWS-0.9.8:
  2168.  
  2169. > (There's a third compatibility hack, which is the reverse of (a): if a
  2170. > function is defined with two or more arguments, and called with a
  2171. > single argument that is a tuple with just as many arguments, the items
  2172. > of this tuple will be used as the arguments.  Although this can (and
  2173. > should!) be done using the built-in function apply() instead, it isn't
  2174. > withdrawn yet.)
  2175.  
  2176. So, as usual, Guido addressed all our questions long before we thought of
  2177. them <grin>.
  2178.  
  2179. Maybe this is cause for hope:  Python has tried a few sets of rules for
  2180. dealing with tuples vs arglists, and for getting the effect of variable
  2181. argument lists, & I believe 0.9.8's rules are the first set I feel I can
  2182. predict in all cases without "looking it up" once a week (of course I'm
  2183. talking about the documented rules -- the reference manual doesn't claim
  2184. you can get away with the example above).
  2185.  
  2186. so-it-feels-like-progress-to-me-ly y'rs  - tim
  2187.  
  2188. Tim Peters   tim@ksr.com
  2189. not speaking for Kendall Square Research Corp
  2190. 
  2191. 
  2192. Received: from relay2.UU.NET by charon.cwi.nl with SMTP
  2193.     id AA20591 (5.65b/3.8/CWI-Amsterdam); Tue, 2 Feb 1993 16:26:45 +0100
  2194. Received: from uunet.uu.net (via LOCALHOST.UU.NET) by relay2.UU.NET with SMTP 
  2195.     (5.61/UUNET-internet-primary) id AA16029; Tue, 2 Feb 93 10:26:46 -0500
  2196. Received: from astro.UUCP by uunet.uu.net with UUCP/RMAIL
  2197.     (queueing-rmail) id 102538.29485; Tue, 2 Feb 1993 10:25:38 EST
  2198. Received: by astro.sunrise.com (/\==/\ Smail3.1.22.1 #22.3)
  2199.     id <m0nJOp7-0003zvC@astro.sunrise.com>; Tue, 2 Feb 93 09:42 EST
  2200. Message-Id: <m0nJOp7-0003zvC@astro.sunrise.com>
  2201. From: drew@sunrise.com (Drew Jenkins)
  2202. Subject: PC Window Bindings?
  2203. To: python-list@cwi.nl
  2204. Date: Tue, 2 Feb 93 9:42:00 EST
  2205. X-Mailer: ELM [version 2.3 PL11]
  2206.  
  2207. Just curious, has anyone created any kind of python bindings
  2208. to the DOS Window environment?
  2209.  
  2210. Drew Jenkins            "Attitude is Everything"
  2211. drew@sunrise.com                 -- Bingen Bart
  2212. 
  2213. 
  2214. Received: from hp.com by charon.cwi.nl with SMTP
  2215.     id AA22361 (5.65b/3.8/CWI-Amsterdam); Tue, 2 Feb 1993 17:22:03 +0100
  2216. Received: from hpavuu.avo.hp.com by hp.com with SMTP
  2217.     (16.8/15.5+IOS 3.13) id AA19886; Tue, 2 Feb 93 08:21:56 -0800
  2218. Received: by hpavun.lf.hp.com
  2219.     (16.8/15.5+IOS 3.22) id AA01060; Tue, 2 Feb 93 11:22:43 -0500
  2220. Date: Tue, 2 Feb 93 11:22:43 -0500
  2221. From: John DeGood <degood@lf.hp.com>
  2222. Message-Id: <9302021622.AA01060@hpavun.lf.hp.com>
  2223. To: drew@sunrise.com
  2224. Subject: Re:  PC Window Bindings?
  2225. Cc: python-list@cwi.nl
  2226.  
  2227. > Just curious, has anyone created any kind of python bindings
  2228. > to the DOS Window environment?
  2229.  
  2230. I was afraid that someone would ask that question someday. :-)
  2231.  
  2232. I began a STDWIN port to Microsoft Windows last year.  Guido suggested
  2233. that I use Python to import and test the STDWIN functions, so I also
  2234. ported Python to run in a text window under Windows.  It turned out to
  2235. definitely be worth the several evenings effort it took to get Python
  2236. running under Windows as it made my STDWIN test/debug/fix cycle so much
  2237. easier.
  2238.  
  2239. This is strictly a "g-job" project that I work on at home in my "spare"
  2240. time.  I have fully implemented many of the STDWIN functions but there
  2241. is still much work remaining.  I don't expect to complete the port
  2242. before mid-year:  the arrival of our second child in November slowed my
  2243. progress!
  2244.  
  2245. I'll post an announcement to this mailing list when I complete the port.
  2246.  
  2247. John DeGood  degood@lf.hp.com
  2248. Hewlett-Packard Little Falls Site (Wilmington, Delaware)
  2249. 
  2250. 
  2251. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  2252.     id AA13934 (5.65b/3.8/CWI-Amsterdam); Sun, 7 Feb 1993 17:59:41 +0100
  2253. Received: by voorn.cwi.nl with SMTP
  2254.     id AA29838 (5.65b/3.8/CWI-Amsterdam); Sun, 7 Feb 1993 17:59:41 +0100
  2255. Message-Id: <9302071659.AA29838=guido@voorn.cwi.nl>
  2256. To: python-list@cwi.nl
  2257. Subject: An ARRAY type for Python
  2258. From: Guido.van.Rossum@cwi.nl
  2259. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  2260. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  2261. Date: Sun, 07 Feb 1993 17:59:40 +0100
  2262. Sender: Guido.van.Rossum@cwi.nl
  2263.  
  2264. About two weeks ago Stefan Esser asked about an array type for Python.
  2265. Actually his question consisted of two parts: (1) he wanted an array
  2266. of objects represented as machine words -- an extension of the string
  2267. type, really; and (2) he wanted to extend Python with a notion of
  2268. multidimensional arrays.
  2269.  
  2270. I've been rather busy lately so I haven't found the time to answer
  2271. either question, so far.  (Sorry Stefan!)  But I did get an idea that
  2272. would address at least the first question.  Let me start by explaining
  2273. some background.
  2274.  
  2275. Python's notion of sequences has always been intended to allow
  2276. extension with new kinds of sequences.  The minimal set of properties
  2277. of a sequence object a is that it has a length, len(a), and that if
  2278. 0 <= i < len(a): a[i] is defined (and for all other i, a[i] is not
  2279. defined).  The semantics of slicing, concatenation and repetition
  2280. (a[i:j], a+b and a*k) are also fixed.  An extension to mutable
  2281. sequences allows assignment to items, to slices, and the list
  2282. operations append and insert.  (The operations remove, index, count,
  2283. reverse and sort are perhaps better seen as specific to the list
  2284. type.)
  2285.  
  2286. The existing sequence types in Python are list, tuple and string.
  2287. But we can easily extend this with arrays of machine integers, say.
  2288. Such an array would behave like a list in most circumstances, but it
  2289. would restrict the values contained in the list to machine integers,
  2290. and therefore a more compact representation can be used.
  2291.  
  2292. I have written a module that creates such arrays, with various types
  2293. of of values (characters, integers of 3 sizes, float and double), and
  2294. placed it on ftp.cwi.nl:/pub/python in file arraymodule.c.  If you
  2295. have dynamic loading in your Python, you can just compile it and
  2296. import it (the file arraymodule.libs should contain the name of the C
  2297. library, e.g. /lib/libc.a; on SGI's -lc_s is better).  Otherwise you
  2298. can add it to your Python interpreter by using the Addmodule.sh script
  2299. and rebuilding Python.
  2300.  
  2301. Here's a short description of my array module.
  2302.  
  2303. ========================================================================
  2304.  
  2305. The module array defines one function.
  2306.  
  2307. array(typecode, initializer)
  2308.     Return a new array whose items are restricted by the typecode,
  2309.     and initialized from the (optional) initializer value.
  2310.     The typecode is a character which defines the item type (users
  2311.     of the getattr() C function in the Python interpreter will
  2312.     recognize this):
  2313.     'c' - charcter
  2314.     'b' - 1-byte signed integer
  2315.     'h' - 2-byte signed integer
  2316.     'l' - 4-byte signed integer
  2317.     'f' - float
  2318.     'd' - double
  2319.     If an initializer is present, it must be a list or a string.
  2320.     The list or string is passed to the new array's fromlist() or
  2321.     fromstring() method (see below) to add initial items to the
  2322.     array.
  2323.  
  2324. Array objects are mutable sequence types and support the following
  2325. data items and methods.
  2326.  
  2327. typecode
  2328.     The typecode character used to create the array
  2329.  
  2330. itemsize
  2331.     The length in bytes of one array item in the internal
  2332.     representation
  2333.  
  2334. append(x)
  2335.     Append a new item with value x to the end of the array.
  2336.  
  2337. insert(i, x)
  2338.     Insert a new item with value x in the array before position i.
  2339.  
  2340. read(f, n)
  2341.     Read n items (as machine values) from the file object f and
  2342.     append them to the end of the array.
  2343.     If less than n items are available, EOFError is raised, but
  2344.     the items that were available are still inserted into the
  2345.     array.
  2346.  
  2347. write(f)
  2348.     Write all items (as machine values) to the file object f.
  2349.  
  2350. fromstring(s)
  2351.     Appends items from the string, interpreting the string as an
  2352.     array of machine values (i.e. as if it had been read from a
  2353.     file using the read() method).
  2354.  
  2355. tostring()
  2356.     Convert the array to an array of machine values and return the
  2357.     string representation (the same sequence of bytes that would
  2358.     be written to a file by the write() method.)
  2359.  
  2360. fromlist(l)
  2361.     Appends items from the list.  This is equivalent to
  2362.         for x in l: a.append(x)
  2363.     except that if there is a type error, the array is unchanged.
  2364.  
  2365. tolist()
  2366.     Convert the array to an ordinary list with the same items.
  2367.  
  2368. When an array object is printed or converted to a string, it is
  2369. represented as array(<typecode>, <initializer>).  The initializer is
  2370. omitted if the array is empty, otherwise it is a string if the
  2371. typecode is 'c', otherwise it is a list of numbers.  The string is
  2372. guaranteed to be able to be converted back to an array with the same
  2373. type and value using reverse quotes (``).  Examples:
  2374.     array('l')
  2375.     array('c', 'hello world')
  2376.     array('l', [1, 2, 3, 4, 5])
  2377.     array('d', [1.0, 2.0, 3.14])
  2378.  
  2379. ========================================================================
  2380.  
  2381. Adding multidimensional arrays to Python is harder, since the
  2382. interpreter currently doesn't know about this concept.  I have some
  2383. ideas that don't require extending the Python syntax, which basically
  2384. boil down to separating the actual array data from a definition of
  2385. how the rows and columns are laid out (e.g. one could transpose an
  2386. array without copying the data).  I'll work on this a little more and
  2387. maybe it'll see the light of day.
  2388.  
  2389. In the mean time, please try out my array module and report any bugs
  2390. or functionality you would like to see added to me -- it may become a
  2391. standard module in the next release.
  2392.  
  2393. Cheers,
  2394.  
  2395. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  2396. 
  2397. 
  2398. Replied: Wed, 10 Feb 1993 10:18:21 +0100
  2399. Replied: "Lance Ellinghouse <lance@markv.com> python-list"
  2400. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  2401.     id AA11988 (5.65b/3.8/CWI-Amsterdam); Wed, 10 Feb 1993 03:45:21 +0100
  2402. From: Lance Ellinghouse <lance@markv.com>
  2403. X-Mailer: SCO System V Mail (version 3.2)
  2404. To: python-list@cwi.nl
  2405. Subject: setting <stdin> to RAW mode???
  2406. Date: Tue, 9 Feb 93 18:45:00 PST
  2407. Message-Id:  <9302091845.aa22168@hermix.markv.com>
  2408.  
  2409. Does anyone know of a quick easy way to set sys.stdin to be in
  2410. RAW mode? (non-buffered, etc)
  2411. I would like to be able to call sys.stdin.read(1) and have it
  2412. return when it really reads 1 char and only 1 char WITHOUT echo...
  2413.  
  2414. Lance Ellinghouse
  2415. lance@markv.com
  2416. 
  2417. 
  2418. To: Lance Ellinghouse <lance@markv.com>
  2419. cc: python-list
  2420. Subject: Re: setting <stdin> to RAW mode??? 
  2421. In-reply-to: Your message of "Tue, 09 Feb 1993 18:45:00 MET."
  2422.              <9302091845.aa22168@hermix.markv.com> 
  2423. From: Guido.van.Rossum@cwi.nl
  2424. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  2425. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  2426. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  2427. Date: Wed, 10 Feb 1993 10:18:21 +0100
  2428. Sender: guido
  2429.  
  2430. >Does anyone know of a quick easy way to set sys.stdin to be in
  2431. >RAW mode? (non-buffered, etc)
  2432. >I would like to be able to call sys.stdin.read(1) and have it
  2433. >return when it really reads 1 char and only 1 char WITHOUT echo...
  2434.  
  2435. Well, you could always try something along the lines of
  2436.  
  2437.     import os
  2438.     sts = os.system('stty raw')
  2439.     if sts: print '"stty raw" failed, exit status', sts
  2440.  
  2441. There's also the optional ioctl module, but I wouldn't call it quick
  2442. and easy, and I have no examples at hand.  It is also (even) less
  2443. portable to use...
  2444.  
  2445. Note that you should probably use "try...finally" to make sure that
  2446. the tty status is reset to normal when the program exits, even if it
  2447. crashes, otherwise your shell finds itself in raw mode.  If you are
  2448. using System V or a derivative, or even SunOS, you can use code like
  2449. this:
  2450.  
  2451.     import os
  2452.     saved_tty_state = os.popen('stty -g', 'r').read()
  2453.     try:
  2454.         sts = os.system('stty raw')
  2455.         ...
  2456.         ...code using raw mode goes here
  2457.         ...
  2458.     finally:
  2459.         sts = os.system('stty ' + saved_tty_state)
  2460.  
  2461. The 'stty -g' command returns a string that compactly encodes all tty
  2462. settings; passing this string as an argument back to stty restores
  2463. these tty settings exactly.
  2464.  
  2465. The "finally" clause gets executed even if your code hits an
  2466. exception, but it does not prevent a stack trace (unlike "except",
  2467. which lets your program continue normally).
  2468.  
  2469. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  2470. 
  2471. 
  2472. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  2473.     id AA06744 (5.65b/3.8/CWI-Amsterdam); Fri, 12 Feb 1993 03:46:18 +0100
  2474. Received: by hermix.markv.com id aa16252; 11 Feb 93 18:45 PST
  2475. From: Lance Ellinghouse <lance@markv.com>
  2476. X-Mailer: SCO System V Mail (version 3.2)
  2477. To: junknews.py@markv.com, python-list@cwi.nl
  2478. Subject: Python program to create groups for Cnews
  2479. Date: Thu, 11 Feb 93 18:35:17 PST
  2480. Message-Id:  <9302111835.aa13609@hermix.markv.com>
  2481.  
  2482. I was tired of creating groups for Cnews by hand..
  2483. I whipped up a little program to do it for me..
  2484. All you have to do is change to vars at the beginning and
  2485. away it goes.. if you find any problems or want to make it better,
  2486. let me know..
  2487. Thanks!
  2488. Lance Ellinghouse
  2489. lance@markv.com
  2490. --- Cut Here:
  2491. #! /usr2/local/bin/python
  2492.  
  2493. # This file takes and scans for files in the "junk" directory
  2494. # of Cnews. It then creates groups based on the Newsgroups: line
  2495. # in these files. It then exits.
  2496.  
  2497. import sys, os, string
  2498.  
  2499. junkdir='/usr/spool/cnews/junk/'
  2500. bindir='/usr2/lib/newsbin/maint/'
  2501.  
  2502. def get_groups(file_name):
  2503.     try:
  2504.         fd=open(file_name,'r')
  2505.     except:
  2506.         print 'cannot open ' + file_name
  2507.         return []
  2508.     while 1:
  2509.         try:
  2510.             line=fd.readline()
  2511.         except EOFError:
  2512.             return []
  2513.         line=string.strip(line)
  2514.         if line[:11] == 'Newsgroups:':
  2515.             groups = string.splitfields(line[12:],',')
  2516.             return groups
  2517.         if len(line) == 0:
  2518.             return []
  2519.  
  2520. def make_groups(groups):
  2521.     for group in groups:
  2522.         os.system(bindir + 'addgroup ' + group + ' y')
  2523.  
  2524. def main():
  2525.     os.chdir(junkdir)
  2526.     for file_name in os.listdir('.'):
  2527.         if file_name not in ['.','..']:
  2528.             print 'processing ' + file_name
  2529.             rtn = make_groups(get_groups(file_name))
  2530.  
  2531. main()
  2532.  
  2533. 
  2534. 
  2535. Replied: Fri, 12 Feb 1993 12:46:40 +0100
  2536. Replied: "Jack Jansen <Jack.Jansen@cwi.nl> python-list@cwi.nl"
  2537. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  2538.     id AA16548 (5.65b/3.8/CWI-Amsterdam); Fri, 12 Feb 1993 10:40:19 +0100
  2539. Received: by schelvis.cwi.nl with SMTP
  2540.     id AA06273 (5.65b/3.8/CWI-Amsterdam); Fri, 12 Feb 1993 10:40:19 +0100
  2541. Message-Id: <9302120940.AA06273=jack@schelvis.cwi.nl>
  2542. To: python-list@cwi.nl
  2543. Subject: Re: Python program to create groups for Cnews 
  2544. In-Reply-To: Message by Lance Ellinghouse <lance@markv.com> ,
  2545.          Thu, 11 Feb 93 18:35:17 PST , <9302111835.aa13609@hermix.markv.com> 
  2546. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  2547. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  2548. X-Last-Band-Seen: de Abbas (Paradiso, 9-2)
  2549. X-Mini-Review: Brilliant! Abba ripped to shreds in a great way!
  2550. Date: Fri, 12 Feb 1993 10:40:18 +0100
  2551. From: Jack Jansen <Jack.Jansen@cwi.nl>
  2552.  
  2553. That message remindss me: does anyone happen to have an rfc822 parser
  2554. in python?
  2555. --
  2556. Jack Jansen        | If I can't dance I don't want to be part of
  2557. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  2558. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  2559. 
  2560. 
  2561. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  2562.     id AA19421 (5.65b/3.8/CWI-Amsterdam); Fri, 12 Feb 1993 12:46:40 +0100
  2563. Received: by voorn.cwi.nl with SMTP
  2564.     id AA04725 (5.65b/3.8/CWI-Amsterdam); Fri, 12 Feb 1993 12:46:40 +0100
  2565. Message-Id: <9302121146.AA04725=guido@voorn.cwi.nl>
  2566. To: Jack Jansen <Jack.Jansen@cwi.nl>
  2567. Cc: python-list@cwi.nl
  2568. Subject: Re: Python program to create groups for Cnews 
  2569. In-Reply-To: Your message of "Fri, 12 Feb 1993 10:40:18 MET."
  2570.              <9302120940.AA06273=jack@schelvis.cwi.nl> 
  2571. From: Guido.van.Rossum@cwi.nl
  2572. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  2573. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  2574. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  2575. Date: Fri, 12 Feb 1993 12:46:39 +0100
  2576. Sender: Guido.van.Rossum@cwi.nl
  2577.  
  2578. >That message remindss me: does anyone happen to have an rfc822 parser
  2579. >in python?
  2580.  
  2581. Try looking at lib/rfc822.py in the 0.9.8 release (or in my home
  2582. directory :-).  It's not complete but does do essentials like parsing
  2583. continuation lines, and gives you a list containing the broken-down
  2584. header.
  2585.  
  2586. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  2587. 
  2588. 
  2589. Received: from mcsun.EU.net by charon.cwi.nl with SMTP
  2590.     id AA20086 (5.65b/3.8/CWI-Amsterdam); Sat, 13 Feb 1993 03:54:27 +0100
  2591. Received: by mcsun.EU.net via EUnet
  2592.     id AA23251 (5.65b/CWI-2.206); Sat, 13 Feb 1993 03:54:26 +0100
  2593. Received: from ghost.uunet.ca (via uunet.ca) by relay1.UU.NET with SMTP 
  2594.     (5.61/UUNET-internet-primary) id AA18653; Fri, 12 Feb 93 21:52:41 -0500
  2595. Received: from snitor by mail.uunet.ca with UUCP id <11310>; Fri, 12 Feb 1993 16:52:44 -0500
  2596. Received: from radium.sni.ca 
  2597.     by snitor.sni.ca (5.61/smail2.5/07-11-92)
  2598.     id AA07346; Fri, 12 Feb 93 13:26:39 -0500
  2599. Received: by radium.sni.CA (5.61/smail2.5/02-09-92)
  2600.     id AA15987; Fri, 12 Feb 93 13:26:29 -0500
  2601. Date:     Fri, 12 Feb 1993 13:26:29 -0500
  2602. From: tracy@snitor.sni.ca (Tracy Tims)
  2603. Message-Id: <9302121826.AA15987@radium.sni.CA>
  2604. To: python-list@cwi.nl
  2605. Subject: mail and news header parsers
  2606.  
  2607. I also have a python function that can parse rfc822 headers, but it is
  2608. designed for parsing general rfc822 forms--news articles, mailboxes,
  2609. rfc822 messages, and various distortions of these.  It is designed to be
  2610. able to recognise the individual messages in a multi-message file, with
  2611. a wide variety of header types.
  2612.  
  2613. I'm using it as the message-parsing backbone for a message-and-file indexing
  2614. system that I'm (slowly) writing.
  2615.  
  2616. Tracy Tims
  2617. 
  2618. 
  2619. Received: from mcsun.EU.net by charon.cwi.nl with SMTP
  2620.     id AA17952 (5.65b/3.8/CWI-Amsterdam); Sat, 20 Feb 1993 00:49:43 +0100
  2621. Received: by mcsun.EU.net via EUnet
  2622.     id AA06945 (5.65b/CWI-2.207); Sat, 20 Feb 1993 00:49:40 +0100
  2623. Received: from ghost.uunet.ca (via uunet.ca) by relay1.UU.NET with SMTP 
  2624.     (5.61/UUNET-internet-primary) id AA09498; Fri, 19 Feb 93 18:48:21 -0500
  2625. Received: from snitor by mail.uunet.ca with UUCP id <9761(2)>; Fri, 19 Feb 1993 18:47:55 -0500
  2626. Received: from radium.sni.ca 
  2627.     by snitor.sni.ca (5.61/smail2.5/07-11-92)
  2628.     id AA10525; Fri, 19 Feb 93 16:59:31 -0500
  2629. Received: by radium.sni.CA (5.61/smail2.5/02-09-92)
  2630.     id AA00310; Fri, 19 Feb 93 16:59:27 -0500
  2631. Date:     Fri, 19 Feb 1993 16:59:27 -0500
  2632. From: tracy@snitor.sni.ca (Tracy Tims)
  2633. Message-Id: <9302192159.AA00310@radium.sni.CA>
  2634. To: Guido.van.Rossum@cwi.nl
  2635. Cc: python-list@cwi.nl
  2636. Subject: Sugar for regular expression groupings.
  2637.  
  2638. I find myself using regex.compile() frequently for parsing lines from
  2639. various data-files.  I write a regular expression that contains a
  2640. number of \( and \) groupings, and then I use slice notation to fetch
  2641. the tokens I want from the line.  Here's an example:
  2642.  
  2643.     format = regex.compile( a_pattern)
  2644.  
  2645.     if format.match( data) != -1:
  2646.         old_ver = data[format.regs[1][0]:format.regs[1][1]]
  2647.         new_ver = data[format.regs[2][0]:format.regs[2][1]]
  2648.         user = data[format.regs[3][0]:format.regs[3][1]]
  2649.         date = data[format.regs[4][0]:format.regs[4][1]]
  2650.         time = data[format.regs[5][0]:format.regs[5][1]]
  2651.         host = data[format.regs[6][0]:format.regs[6][1]]
  2652.         dir = data[format.regs[7][0]:format.regs[7][1]]
  2653.  
  2654. I use the slice notation/regex register code over and over again, in
  2655. many programs.  This is so common that perhaps there should be a
  2656. clearer way to do this.  (I've seen the idiom in fpformat.py, and it
  2657. doesn't make me completely happy.)
  2658.  
  2659. What if a compiled regular expression object had an attribute which
  2660. was a reference to the last string on which it sucessfully matched (I
  2661. think this is a good idea anyway--I have always been uncomfortable
  2662. with the fact that a regular expression object only contains half of
  2663. the information needed to extract groups), and if it had a simple
  2664. method for returning groups out of the matched string?
  2665.  
  2666. I could reduce the example above to the following:
  2667.  
  2668.     if format.match( data) != -1:
  2669.         old_ver, new_ver, user, date, time, host, dir \
  2670.             = format.groups(1,2,3,4,5,6,7)
  2671.  
  2672. Code using the groups() method is easier to modify and maintain
  2673. because it doesn't have the internal interdependencies that the first
  2674. example has (and the fpformat.py idiom also has).
  2675.  
  2676. Tracy Tims
  2677.  
  2678.  
  2679. 
  2680. 
  2681. Replied: Sun, 21 Feb 1993 18:36:50 +0100
  2682. Replied: "python-list "
  2683. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  2684.     id AA26445 (5.65b/3.8/CWI-Amsterdam); Sat, 20 Feb 1993 03:04:20 +0100
  2685. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  2686.     id AA01551; Fri, 19 Feb 1993 21:00:20 -0500
  2687. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  2688.     id AA27070; Fri, 19 Feb 93 20:58:13 EST
  2689. Received: by kaos.ksr.com (4.1/KSR-2.0)
  2690.     id AA27540; Fri, 19 Feb 93 20:58:09 EST
  2691. Message-Id: <9302200158.AA27540@kaos.ksr.com>
  2692. To: tracy@snitor.sni.ca
  2693. Subject: Re: Sugar for regular expression groupings.
  2694. Cc: python-list@cwi.nl
  2695. Date: Fri, 19 Feb 93 20:58:08 EST
  2696. From: Tim Peters <tim@ksr.com>
  2697.  
  2698. > [Tracy Tims writes ...]
  2699. > I find myself using regex.compile() frequently for parsing lines from
  2700. > various data-files.  ...
  2701. > [notes that breaking out fields is clumsy & error-prone, a la ...]
  2702. >
  2703. >       format = regex.compile( a_pattern)
  2704. >
  2705. >       if format.match( data) != -1:
  2706. >               old_ver = data[format.regs[1][0]:format.regs[1][1]]
  2707. >               new_ver = data[format.regs[2][0]:format.regs[2][1]]
  2708. >               user = data[format.regs[3][0]:format.regs[3][1]]
  2709. >               date = data[format.regs[4][0]:format.regs[4][1]]
  2710. >               time = data[format.regs[5][0]:format.regs[5][1]]
  2711. >               host = data[format.regs[6][0]:format.regs[6][1]]
  2712. >               dir = data[format.regs[7][0]:format.regs[7][1]]
  2713. > ...
  2714. > [but with some changes ...]
  2715. > I could reduce the example above to the following:
  2716. >
  2717. >       if format.match( data) != -1:
  2718. >               old_ver, new_ver, user, date, time, host, dir \
  2719. >                       = format.groups(1,2,3,4,5,6,7)
  2720. >
  2721. > Code using the groups() method is easier to modify and maintain
  2722. > because it doesn't have the internal interdependencies that the first
  2723. > example has (and the fpformat.py idiom also has).
  2724.  
  2725. I'll whine louder <grin>:  even given those changes, you still have a
  2726. maintenance nightmare because of the ubiquitous reliance on meaningless
  2727. little integers to denote the fields.  If the format of the data file
  2728. changes, or even if it doesn't but you decide you need to extract some
  2729. more info "in the middle" (a common desire as applications grow fancier),
  2730. the relative indices of the parentheses may change.  Then you've got to
  2731. track down all the references in the code & change 'em.
  2732.  
  2733. Attached is module regex2.py, a homegrown way to worm around those
  2734. problems.  I haven't gotten around to documenting it, but an example
  2735. should make it clear enough to understand what the code is doing.  I'll
  2736. use the regexp from fpformat.py for familiarity's sake:
  2737.  
  2738. >>> import regex2
  2739. >>> fpre = '^\([-+]?\)0*\([0-9]*\)\(\(\.[0-9]*\)?\)\(\([eE][-+]?[0-9]+\)?\)$'
  2740. >>> decoder = regex2.compile( fpre, 'all','sign','int','frac','junk','exp')
  2741. >>> decoder.match('-2.3e45')
  2742. 7
  2743. >>> decoder.matches_by_index(0,2,2,6)
  2744. ('-2.3e45', '2', '2', 'e45')
  2745. >>> decoder.matches_by_name('sign','int','frac','exp')
  2746. ('-', '2', '.3', 'e45')
  2747. >>> decoder.match('abc')
  2748. -1
  2749. >>> decoder.matches_by_name('int')
  2750. regex2: last match failed
  2751. Stack backtrace (innermost last):
  2752.   File "<stdin>", line 1
  2753.   File "./regex2.py", line 41
  2754.     raise error
  2755. >>>
  2756.  
  2757. So your "groups" method is named "matches_by_index" here, & there's also
  2758. a "matches_by_name" method that confines the dependence on little
  2759. integers to a single line (the fields are (optionally) named at the time
  2760. the regexp is compiled).  It also arranges to gripe if a "matches_by_..."
  2761. method is invoked when the preceding search or match attempt failed; that
  2762. may or may not be a feature (eye of the beholder; obviously, I like it
  2763. that way).
  2764.  
  2765. Give it a try & see how you like it!  This kind of thing is very easy to
  2766. do in Python, so play around & see if you can come up with something you
  2767. like better.
  2768.  
  2769. the-trick-to-motivating-guido-to-change-python-is-to-come-up-with-
  2770.    something-*he*-likes-better<grin>-ly y'rs  - tim
  2771.  
  2772. Tim Peters   tim@ksr.com
  2773. not speaking for Kendall Square Research Corp
  2774.  
  2775. Module regex2.py:
  2776.  
  2777. import regex
  2778.  
  2779. error = 'regex2: last match failed'
  2780.  
  2781. def compile( pattern, *field_names ):
  2782.     answer = _Regex2()
  2783.     answer.pattern = pattern            # currently unused
  2784.     answer.compiled_re = regex.compile( pattern )
  2785.     answer.matched_string = None
  2786.     answer.name2index = {}
  2787.     i = 0
  2788.     for name in field_names:
  2789.         answer.name2index[name] = i
  2790.         i = i + 1
  2791.     return answer
  2792.  
  2793. class _Regex2:
  2794.     def match( self, string ):
  2795.         a = self.compiled_re.match( string )
  2796.         if a >= 0: self.matched_string = string
  2797.         else:      self.matched_string = None
  2798.         return a
  2799.  
  2800.     def search( self, string ):
  2801.         a = self.compiled_re.search( string )
  2802.         if a >= 0: self.matched_string = string
  2803.         else:      self.matched_string = None
  2804.         return a
  2805.  
  2806.     def matches_by_index( self, *indices ):
  2807.         if self.matched_string is None:
  2808.             raise error
  2809.         answer = ()
  2810.         for n in indices:
  2811.             start, end = self.compiled_re.regs[n]
  2812.             answer = answer + (self.matched_string[start:end],)
  2813.         return answer
  2814.  
  2815.     def matches_by_name( self, *field_names ):
  2816.         if self.matched_string is None:
  2817.             raise error
  2818.         answer = ()
  2819.         for name in field_names:
  2820.             i = self.name2index[name]
  2821.             start, end = self.compiled_re.regs[i]
  2822.             answer = answer + (self.matched_string[start:end],)
  2823.         return answer
  2824.  
  2825. END OF MSG
  2826. 
  2827. 
  2828. To: python-list
  2829. Subject: Re: Sugar for regular expression groupings. 
  2830. In-reply-to: Your message of "Fri, 19 Feb 1993 20:58:08 MET."
  2831.              <9302200158.AA27540@kaos.ksr.com> 
  2832. From: Guido.van.Rossum@cwi.nl
  2833. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  2834. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  2835. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  2836. Date: Sun, 21 Feb 1993 18:36:50 +0100
  2837. Sender: guido
  2838.  
  2839. Thanks for your ideas, Tracy and Tim!
  2840.  
  2841. I like the idea of saving a reference to the last matched string and
  2842. providing a varargs function to access substrings.  I'll try to put
  2843. this (as C code) in the next release.  I don't think the interface to
  2844. access substrings by name instead of by number buys you much (except
  2845. an advantage over Perl :-).  You can always define constants to name
  2846. the substrings near the place where you write down the pattern.
  2847.  
  2848. Off to coding,
  2849.  
  2850. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  2851. 
  2852. 
  2853. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  2854.     id AA23418 (5.65b/3.8/CWI-Amsterdam); Mon, 22 Feb 1993 03:47:35 +0100
  2855. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  2856.     id AA00698; Sun, 21 Feb 1993 21:43:24 -0500
  2857. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  2858.     id AA04898; Sun, 21 Feb 93 21:41:25 EST
  2859. Received: by kaos.ksr.com (4.1/KSR-2.0)
  2860.     id AA07381; Sun, 21 Feb 93 21:41:21 EST
  2861. Message-Id: <9302220241.AA07381@kaos.ksr.com>
  2862. To: Guido.van.Rossum@cwi.nl
  2863. Subject: Re: Sugar for regular expression groupings.
  2864. Cc: python-list@cwi.nl
  2865. Date: Sun, 21 Feb 93 21:41:19 EST
  2866. From: Tim Peters <tim@ksr.com>
  2867. Status: RO
  2868.  
  2869. > [guido]
  2870. > ...
  2871. > I like the idea of saving a reference to the last matched string and
  2872. > providing a varargs function to access substrings.  I'll try to put
  2873. > this (as C code) in the next release.
  2874.  
  2875. Cool!
  2876.  
  2877. > I don't think the interface to access substrings by name instead of by
  2878. > number buys you much
  2879.  
  2880. Not initially, no ... it's a year later when the format changes that the
  2881. pain begins <smile>.  Still, I wouldn't _recommend_ people generally use
  2882. a name interface either, cuz no matter how it's done it's gonna be pretty
  2883. slow.  For that reason, I don't use a name interface myself for regexp-
  2884. crunching on large volumes of data.
  2885.  
  2886. > (except an advantage over Perl :-).
  2887.  
  2888. Having a regexp _object_ is an advantage over Perl already; the Perl
  2889. folks ask for "something like that" regularly.  But getting the effect of
  2890. named fields is already easy in Perl.  E.g., for the fpformat.py example:
  2891.  
  2892. >>> fpre = '^\([-+]?\)0*\([0-9]*\)\(\(\.[0-9]*\)?\)\(\([eE][-+]?[0-9]+\)?\)$'
  2893. >>> decoder = regex2.compile( fpre, 'all','sign','int','frac','junk','exp')
  2894. >>> decoder.match('-2.3e45')
  2895. 7
  2896. >>> decoder.matches_by_name('sign','int','frac','exp')
  2897. ('-', '2', '.3', 'e45')
  2898.  
  2899. In idiomatic Perl that looks like:
  2900.  
  2901. $fpre = '^([-+]?)0*(\d*)((\.\d*)?)((e[-+]?\d+)?)$';
  2902. ($sign,$int,$frac,$junk,$exp) = '-2.3e45' =~ /$fpre/io;
  2903. print "$sign $int $frac $exp\n";
  2904.  
  2905. which prints "- 2 .3 e45".  A pretty close equivalent in Python would be
  2906. if a compiled regexp's search method returned a tuple with a number of
  2907. elements equal to the number of meta-parentheses in the regexp:
  2908.  
  2909. >>> sign,int,frac,junk,exp = decoder.hypothetical_search('-2.3e45')
  2910.  
  2911. where `sign' etc are bound to None if the search fails.  This way has
  2912. attractions too.
  2913.  
  2914. Lots of ways to skin this cat <smile>!  I hope someone who does a lot of
  2915. regexp crunching (I really don't) tries out several approaches & says what
  2916. they like best.
  2917.  
  2918. > You can always define constants to name the substrings near the place
  2919. > where you write down the pattern.
  2920.  
  2921. That's fine by me, although there's a little danger from unintended
  2922. namespace collisions.
  2923.  
  2924. A suggestion for people who intend to do that:  Instead of defining the
  2925. "constants" like this:
  2926.  
  2927.     ALL  = 0
  2928.     SIGN = 1
  2929.     INT  = 2
  2930.     FRAC = 3
  2931.     JUNK = 4
  2932.     EXP  = 5
  2933.  
  2934. Do it like this:
  2935.  
  2936.     [ALL, SIGN, INT, FRAC, JUNK, EXP] = range(6)
  2937.  
  2938. You'll be glad you did when things change ...
  2939.  
  2940. agreeably y'rs  - tim
  2941.  
  2942. Tim Peters   tim@ksr.com
  2943. not speaking for Kendall Square Research Corp
  2944. 
  2945. 
  2946. Received: from mcsun.EU.net by charon.cwi.nl with SMTP
  2947.     id AA08464 (5.65b/3.8/CWI-Amsterdam); Mon, 22 Feb 1993 16:55:01 +0100
  2948. Received: by mcsun.EU.net via EUnet
  2949.     id AA00746 (5.65b/CWI-2.207); Mon, 22 Feb 1993 16:55:00 +0100
  2950. Received: from ghost.uunet.ca (via uunet.ca) by relay1.UU.NET with SMTP 
  2951.     (5.61/UUNET-internet-primary) id AA07069; Mon, 22 Feb 93 10:51:02 -0500
  2952. Received: from snitor by mail.uunet.ca with UUCP id <9670(1)>; Mon, 22 Feb 1993 10:50:50 -0500
  2953. Received: from radium.sni.ca 
  2954.     by snitor.sni.ca (5.61/smail2.5/07-11-92)
  2955.     id AA01368; Mon, 22 Feb 93 10:07:24 -0500
  2956. Received: by radium.sni.CA (5.61/smail2.5/02-09-92)
  2957.     id AA03386; Mon, 22 Feb 93 10:07:13 -0500
  2958. Date:     Mon, 22 Feb 1993 10:07:13 -0500
  2959. From: tracy@snitor.sni.ca (Tracy Tims)
  2960. Message-Id: <9302221507.AA03386@radium.sni.CA>
  2961. To: tim@ksr.com
  2962. Cc: python-list@cwi.nl
  2963. In-Reply-To: Tim Peters's message of Fri, 19 Feb 1993 20:58:08 -0500 <9302200158.AA27540@kaos.ksr.com>
  2964. Subject: Sugar for regular expression groupings.
  2965.  
  2966. I ended up not writing my own regex class with symbolic group names
  2967. for two reasons: if the feature is supplied in the standard python
  2968. module it will be faster, and it will be more portable (or
  2969. distributable).
  2970.  
  2971. I also figured that Guido would be more likely to add a simpler
  2972. solution, because it will be less work for most of the benefits.  I
  2973. can live with integer group names.  I'll either symbolically name
  2974. them, use them as is, or store complete argument lists for groups()
  2975. along with my regular expressions.
  2976.  
  2977. If necessary, symbolic group names can be added later without
  2978. obsoleting 'regs' or the additions I propose.
  2979.  
  2980.     Improvement 1:
  2981.         Add an optional dictionary attribute to regex objects.
  2982.             Ex: regex.groupnames
  2983.  
  2984.         Add varargs to the compile() method that will automatically
  2985.         initially define the optional dictionary.
  2986.             Ex: regex.compile( re, 'group_1_name', 'group_2_name')
  2987.  
  2988.         Modify groups() so that if a string is given as a
  2989.         group-selector argument it is used to index the dictionary to
  2990.         obtain the group number.
  2991.             Ex: decode.groups( 1, 'group_2_name')
  2992.  
  2993.         This ends up looking like your solution, but the relationship
  2994.         between 'regs', groups(), and 'groupnames' is explicit.  This
  2995.         is useful because it increases the number of "fruitful
  2996.         interactions".
  2997.  
  2998.     Improvement 2:
  2999.         Add syntax to regular expressions so that groups can be named
  3000.         in place, yielding the group dictionary.  (This is a *big*
  3001.         advantage over perl.)
  3002.  
  3003.         For example:
  3004.             re = '[^0-9]*\(<number>[0-9]+\)[ \t]+\(<label>[A-Za-z_-.]+\)'
  3005.             decode = regex.compile( re)
  3006.             n, l = decode.groups( 'number', 'label')
  3007.  
  3008.         I like this idea, because then I can build complicated regular
  3009.         expressions in substrings, and then catenate them together
  3010.         into the final regular expression before compiling.  It also
  3011.         completely eliminates group-counting, and it provides a visual
  3012.         indication of which groups are just for grouping, and which
  3013.         are for substring extraction.
  3014.  
  3015. But what python really needs are LALR(1) parser objects, don't you
  3016. think?
  3017.  
  3018. Tracy Tims
  3019. 
  3020. 
  3021. Replied: Tue, 23 Feb 1993 02:03:23 +0100
  3022. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list"
  3023. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  3024.     id AA11086 (5.65b/3.8/CWI-Amsterdam); Mon, 22 Feb 1993 18:50:16 +0100
  3025. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  3026.     id AA09230; Mon, 22 Feb 93 09:50:21 -0800
  3027. Received: by eng2.sequent.com (5.65/1.34)
  3028.     id AA01658; Mon, 22 Feb 93 09:50:00 -0800
  3029. Message-Id: <9302221750.AA01658@eng2.sequent.com>
  3030. To: tracy@snitor.sni.ca (Tracy Tims)
  3031. Cc: tim@ksr.com, python-list@cwi.nl
  3032. Subject: Re: Sugar for regular expression groupings. 
  3033. Priority: Normal
  3034. Precedence: first-class
  3035. Organization: Sequent Computer Systems, Inc.
  3036.               Service Technology - MailStop: WIL2-610
  3037.           15450 S.W. Koll Parkway
  3038.               Beaverton, OR  97006
  3039. X-Phone: (503) 578-4404
  3040. X-Fax: (503) 578-4540
  3041. X-Uucp: ...!uunet!sequent!jaap
  3042. X-Internet: jaap@sequent.com
  3043. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  3044.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  3045.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  3046. In-Reply-To: Tracy Tims's message of Mon, 22 Feb 1993 10:07:13 -0500.
  3047.              <9302221507.AA03386@radium.sni.CA> 
  3048. Date: Mon, 22 Feb 1993 09:49:59 -0800
  3049. From: Jaap Vermeulen <jaap@sequent.com>
  3050.  
  3051.  
  3052. |     Improvement 2:
  3053. |         Add syntax to regular expressions so that groups can be named
  3054. |         in place, yielding the group dictionary.  (This is a *big*
  3055. |         advantage over perl.)
  3056.  
  3057. I stronly second this improvement.  How often do I just guess which
  3058. subexpression yields what result?  Often, since I always have trouble
  3059. counting nested subexpressions (and I'm sure I'm not the only one).
  3060.  
  3061. | But what python really needs are LALR(1) parser objects, don't you
  3062. | think?
  3063.  
  3064. Yes, that would solve a lot of other problems I encountered while
  3065. parsing *long* strings.
  3066.  
  3067. $0.02
  3068.  
  3069.     -Jaap-
  3070. --
  3071. Jaap Vermeulen                    +--------------------------+
  3072.                         | Sequent Computer Systems |
  3073.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  3074.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  3075. 
  3076. 
  3077. To: Jaap Vermeulen <jaap@sequent.com>
  3078. cc: python-list
  3079. Subject: Re: Sugar for regular expression groupings. 
  3080. In-reply-to: Your message of "Mon, 22 Feb 1993 09:49:59 MET."
  3081.              <9302221750.AA01658@eng2.sequent.com> 
  3082. From: Guido.van.Rossum@cwi.nl
  3083. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  3084. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  3085. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3086. Date: Tue, 23 Feb 1993 02:03:23 +0100
  3087. Sender: guido
  3088.  
  3089. >
  3090. >|     Improvement 2:
  3091. >|         Add syntax to regular expressions so that groups can be named
  3092. >|         in place, yielding the group dictionary.  (This is a *big*
  3093. >|         advantage over perl.)
  3094. >
  3095. >I stronly second this improvement.  How often do I just guess which
  3096. >subexpression yields what result?  Often, since I always have trouble
  3097. >counting nested subexpressions (and I'm sure I'm not the only one).
  3098.  
  3099. I'm afraid the trouble with this one is that the syntax of Python
  3100. regular expressions is defined by the GNU Emacs regular expression
  3101. package.  I am using a Finnish reimplementation that is free of the
  3102. GNU copyleft, but which follows the GNU syntax and interface quite
  3103. precisely so it is possible to plug in the GNU Emacs code instead
  3104. (which was slightly faster and a lot smaller if I remember it well).
  3105.  
  3106. I can't say I understand this code and I would like not to modify it.
  3107. So what can I do?  Is it really that hard to count occurrences of \(?
  3108.  
  3109. >| But what python really needs are LALR(1) parser objects, don't you
  3110. >| think?
  3111. >
  3112. >Yes, that would solve a lot of other problems I encountered while
  3113. >parsing *long* strings.
  3114.  
  3115. That's an interesting thought.  Unfortunately the only LALR(1) parser
  3116. generators I know of are Yacc and Bison, and neither appears to be
  3117. easily modified to generate its tables in a form different that C data
  3118. structures (anyone here to contradict this statement?).  Would you
  3119. folks settle for a recursive descent parser generator (like the one
  3120. used to build the Python parser)?  That one I know how to hack...
  3121.  
  3122. 'Night,
  3123.  
  3124. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3125. 
  3126. 
  3127. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3128.     id AA04715 (5.65b/3.8/CWI-Amsterdam); Tue, 23 Feb 1993 02:03:24 +0100
  3129. Received: by voorn.cwi.nl with SMTP
  3130.     id AA27447 (5.65b/3.8/CWI-Amsterdam); Tue, 23 Feb 1993 02:03:23 +0100
  3131. Message-Id: <9302230103.AA27447=guido@voorn.cwi.nl>
  3132. To: Jaap Vermeulen <jaap@sequent.com>
  3133. Cc: python-list@cwi.nl
  3134. Subject: Re: Sugar for regular expression groupings. 
  3135. In-Reply-To: Your message of "Mon, 22 Feb 1993 09:49:59 MET."
  3136.              <9302221750.AA01658@eng2.sequent.com> 
  3137. From: Guido.van.Rossum@cwi.nl
  3138. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  3139. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  3140. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3141. Date: Tue, 23 Feb 1993 02:03:23 +0100
  3142. Sender: Guido.van.Rossum@cwi.nl
  3143.  
  3144. >
  3145. >|     Improvement 2:
  3146. >|         Add syntax to regular expressions so that groups can be named
  3147. >|         in place, yielding the group dictionary.  (This is a *big*
  3148. >|         advantage over perl.)
  3149. >
  3150. >I stronly second this improvement.  How often do I just guess which
  3151. >subexpression yields what result?  Often, since I always have trouble
  3152. >counting nested subexpressions (and I'm sure I'm not the only one).
  3153.  
  3154. I'm afraid the trouble with this one is that the syntax of Python
  3155. regular expressions is defined by the GNU Emacs regular expression
  3156. package.  I am using a Finnish reimplementation that is free of the
  3157. GNU copyleft, but which follows the GNU syntax and interface quite
  3158. precisely so it is possible to plug in the GNU Emacs code instead
  3159. (which was slightly faster and a lot smaller if I remember it well).
  3160.  
  3161. I can't say I understand this code and I would like not to modify it.
  3162. So what can I do?  Is it really that hard to count occurrences of \(?
  3163.  
  3164. >| But what python really needs are LALR(1) parser objects, don't you
  3165. >| think?
  3166. >
  3167. >Yes, that would solve a lot of other problems I encountered while
  3168. >parsing *long* strings.
  3169.  
  3170. That's an interesting thought.  Unfortunately the only LALR(1) parser
  3171. generators I know of are Yacc and Bison, and neither appears to be
  3172. easily modified to generate its tables in a form different that C data
  3173. structures (anyone here to contradict this statement?).  Would you
  3174. folks settle for a recursive descent parser generator (like the one
  3175. used to build the Python parser)?  That one I know how to hack...
  3176.  
  3177. 'Night,
  3178.  
  3179. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3180. 
  3181. 
  3182. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  3183.     id AA11635 (5.65b/3.8/CWI-Amsterdam); Tue, 23 Feb 1993 07:03:25 +0100
  3184. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  3185.     id AA21210; Tue, 23 Feb 1993 00:59:55 -0500
  3186. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  3187.     id AA20154; Tue, 23 Feb 93 01:02:53 EST
  3188. Received: by kaos.ksr.com (4.1/KSR-2.0)
  3189.     id AA00153; Tue, 23 Feb 93 01:02:52 EST
  3190. Message-Id: <9302230602.AA00153@kaos.ksr.com>
  3191. To: tracy@snitor.sni.ca, jaap@sequent.com, Guido.van.Rossum@cwi.nl
  3192. Subject: Re: Sugar for regular expression groupings.
  3193. Cc: python-list@cwi.nl
  3194. Date: Tue, 23 Feb 93 01:02:51 EST
  3195. From: Tim Peters <tim@ksr.com>
  3196.  
  3197. > [tracy]
  3198. > I ended up not writing my own regex class with symbolic group names for
  3199. > two reasons:  if the feature is supplied in the standard python module
  3200. > it will be faster, and it will be more portable (or distributable).
  3201.  
  3202. Agree "faster" is likely, but don't understand the portable/distributable
  3203. point:  a module coded _in_ standard Python is quite portable!  The
  3204. advantage to doing it that way is it gives people a chance to experiment
  3205. with the interface, before freezing it into the standard distribution.
  3206.  
  3207. > ... I can live with integer group names.
  3208.  
  3209. Me too!
  3210.  
  3211. > [various improvements:  groupnames attribute; optional varargs to
  3212. >  'compile' to initialize groupnames; modify 'groups' method to allow
  3213. >  strings (names) in addition to integer indices]
  3214. >
  3215. >         This ends up looking like your solution, but the relationship
  3216. >         between 'regs', groups(), and 'groupnames' is explicit.  This
  3217. >         is useful because it increases the number of "fruitful
  3218. >         interactions".
  3219.  
  3220. Well, there's nothing to stop you from writing a portable module, in std
  3221. Python, that does exactly all that today.  If you did that & distributed
  3222. the module, and people liked it a lot, Guido might get interested in
  3223. hacking a C version <grin>.
  3224.  
  3225. >     Improvement 2:
  3226. >         Add syntax to regular expressions so that groups can be named
  3227. >         in place, yielding the group dictionary.  (This is a *big*
  3228. >         advantage over perl.)
  3229. >
  3230. >         For example:
  3231. >             re = '[^0-9]*\(<number>[0-9]+\)[ \t]+\(<label>[A-Za-z_-.]+\)'
  3232. >             decode = regex.compile( re)
  3233. >             n, l = decode.groups( 'number', 'label')
  3234. >
  3235. >         I like this idea, because then I can build complicated regular
  3236. >         expressions in substrings, and then catenate them together
  3237. >         into the final regular expression before compiling.  It also
  3238. >         completely eliminates group-counting, and it provides a visual
  3239. >         indication of which groups are just for grouping, and which
  3240. >         are for substring extraction.
  3241.  
  3242. Agree that _is_ nice.  But again, it's something you _can_ do today, in
  3243. your own Python module (in your compile method, you "just" need to
  3244. analyze the pattern string before invoking regex.compile, stripping out
  3245. the '<name>' portions and saving away the derived name->index dict;
  3246. there's really no need to touch the current regex implementation, except
  3247. in that it's likely you'll wind up using more sets of parens than
  3248. regexmodule is currently compiled to handle).
  3249.  
  3250. > But what python really needs are LALR(1) parser objects, don't you
  3251. > think?
  3252.  
  3253. Hard to say!  I confess I came to UNIX(tm) late in life, & never did
  3254. grasp the fascination with regexps.  I find them awfully cryptic &
  3255. clumsy as soon as they go beyond the trivial.  E.g., here's one from
  3256. python-mode.el, to match a Python line that opens a code block:
  3257.  
  3258. \\([^#'\n\\]\\|'\\([^'\n\\]\\|\\\\.\\)*'\\|\\\\\n\\)*:\\([ \t]\\|\\\\\n\\)*\\(#.*\\)?$
  3259.  
  3260. I can't even read that anymore!  Least not without a lot of tedious
  3261. effort.
  3262.  
  3263. A std parsing approach might be better after all (how many more desperate
  3264. net msgs will we read asking how to capture the concept of nesting
  3265. brackets via regexps <0.9 grin>?).  But not sure:  the only truly
  3266. _pleasant_ pattern-matching language I've used is SNOBOL4, & even it was
  3267. clumsy for dealing with left recursion.
  3268.  
  3269. Suspect we agree that regexps aren't the right way to go for complex
  3270. pattern-matching tasks.  On the other hand, I do think they're fine for
  3271. simple tasks, so maybe keeping them clusmy to use is doing most users a
  3272. favor <0.9 grin>.
  3273.  
  3274. > [guido]
  3275. > I'm afraid the trouble with this one [tracy's '<name>' extension] is
  3276. > that the syntax of Python regular expressions is defined by the GNU
  3277. > Emacs regular expression package.
  3278.  
  3279. Ya, but it's not an essential extension -- the <name> constructs are
  3280. syntactic sugar that could be stripped out before the Emacs package is
  3281. invoked.  Not saying you _should_, just saying that it's not hard to do.
  3282.  
  3283. > ... Is it really that hard to count occurrences of \(?
  3284.  
  3285. Well, it _is_ error-prone:  I remember when quoted strings were introduced
  3286. into Fortran, and hearing "is it really that hard to count the number of
  3287. characters in a Hollerith?" (hint:  the answer is "no" <grin>).
  3288.  
  3289. I think what it _does_ do is impose an unnatural implementation layer
  3290. between the way we think of the problem & the way we need to code the
  3291. solution.  On the other hand, in those cases where regexps get so fancy
  3292. that the need for counting parens goes above 3 (truly my _comfortable_
  3293. mental limit!), regexps probably aren't the right tool for the job anyway
  3294. ...
  3295.  
  3296. > ...
  3297. > Would you folks settle for a recursive descent parser generator (like
  3298. > the one used to build the Python parser)?  That one I know how to
  3299. > hack...
  3300.  
  3301. I'd like to see someone suggest a specific interface, & code it up in
  3302. Python, so we could get a feel for how it works in practice.
  3303.  
  3304. In the meantime, I believe everyone agrees that a regex method supporting
  3305. varargs "integer group names" would be a valuable extension -- right?
  3306.  
  3307. mostly-just-thinking-out-loud-ly y'rs  - tim
  3308.  
  3309. Tim Peters   tim@ksr.com
  3310. not speaking for Kendall Square Research Corp
  3311. 
  3312. 
  3313. Received: from mcsun.EU.net by charon.cwi.nl with SMTP
  3314.     id AA07047 (5.65b/3.8/CWI-Amsterdam); Tue, 23 Feb 1993 16:24:23 +0100
  3315. Received: by mcsun.EU.net via EUnet
  3316.     id AA25585 (5.65b/CWI-2.207); Tue, 23 Feb 1993 16:24:22 +0100
  3317. Received: from ghost.uunet.ca (via uunet.ca) by relay1.UU.NET with SMTP 
  3318.     (5.61/UUNET-internet-primary) id AA19004; Tue, 23 Feb 93 10:23:55 -0500
  3319. Received: from snitor by mail.uunet.ca with UUCP id <9657(2)>; Tue, 23 Feb 1993 10:23:37 -0500
  3320. Received: from radium.sni.ca 
  3321.     by snitor.sni.ca (5.61/smail2.5/07-11-92)
  3322.     id AA20019; Tue, 23 Feb 93 09:50:39 -0500
  3323. Received: by radium.sni.CA (5.61/smail2.5/02-09-92)
  3324.     id AA04624; Tue, 23 Feb 93 09:50:21 -0500
  3325. Date:     Tue, 23 Feb 1993 09:50:21 -0500
  3326. From: tracy@snitor.sni.ca (Tracy Tims)
  3327. Message-Id: <9302231450.AA04624@radium.sni.CA>
  3328. To: tim@ksr.com
  3329. Cc: python-list@cwi.nl
  3330. In-Reply-To: Tim Peters's message of Tue, 23 Feb 1993 01:02:51 -0500 <9302230602.AA00153@kaos.ksr.com>
  3331. Subject: Distributing programs and grouping modules.
  3332.  
  3333. If I write a python program and it doesn't require any additional
  3334. "independent" modules, then I can just bundle up the program and send
  3335. it to someone, and they only have one item to install and maintain.
  3336.  
  3337. If I write a regular expression module, and then use that in my
  3338. programs, everyone who wants to use one of my programs will have to
  3339. obtain and install my regular expression module as well.
  3340.  
  3341. This becomes an arbitrarily large problem, because I could improve
  3342. other python modules in the same way, and because other people could
  3343. also write their own improvements.
  3344.  
  3345. It has been my experience that the greater the degree of idiosyncracy
  3346. in a program's environment (libraries, language extensions, etc, etc)
  3347. the more difficult it will be to install and maintain the program.
  3348. This is especially true if the environment into which the program is
  3349. being installed is also idiosyncratic.
  3350.  
  3351. Imagine, after a few years of code sharing with other python lovers, a
  3352. single directory of python programs and modules which contained
  3353. several distinct re-interpretations of regular expressions.  Yuck.
  3354.  
  3355. I suppose one could write a program "packager" that would perform a
  3356. closure over "import" and then output the list of files containing the
  3357. non-standard modules required for the program.
  3358.  
  3359. Perhaps this points up a weakness in python.  There is a good
  3360. modularization mechanism, but the concept of 'program' and 'library'
  3361. isn't yet well developed.
  3362.  
  3363. Could this be handled by expanding the semantics of 'import' so that
  3364. it would also scan for modules in subdirectories of directories on the
  3365. path?  If it did this, multi-module programs or programs with
  3366. idiosyncratic support modules could be installed into their own
  3367. subdirectories.  (The import statement would need to be changed to do
  3368. some variant of "first search the directory containing the module
  3369. executing the 'import' statement" in order to disambiguate modules
  3370. with the same name.)
  3371.  
  3372. This is interesting to me, because most of my python scripts are
  3373. multi-module.  I even write my "shell-scripts" as modules, and I use a
  3374. special module for finding and invoking them, so that all of the
  3375. python programs in my bin look like this...
  3376.  
  3377.     #! /usr/local/bin/python
  3378.     import startscript
  3379.  
  3380. The startscript module is sort of neat, because it knows whether or
  3381. not the module is being run as a standalone command (and therefore
  3382. main() should be called) or whether it is being imported interactively
  3383. for debugging.  (It also means that almost all of my python code is in
  3384. .pyc files.)
  3385.  
  3386. Tracy
  3387. 
  3388. 
  3389. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  3390.     id AA09352 (5.65b/3.8/CWI-Amsterdam); Tue, 23 Feb 1993 18:23:27 +0100
  3391. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11720>; Tue, 23 Feb 1993 09:23:09 PST
  3392. Received: by eros.EuroPARC.Xerox.COM with SMTP
  3393.     (5.65c/IDA-1.2.9) id AA00241; Tue, 23 Feb 1993 17:22:31 GMT
  3394. Message-Id: <199302231722.AA00241@eros.EuroPARC.Xerox.COM>
  3395. To: python-list@cwi.nl
  3396. Subject: Re: Distributing programs and grouping modules. 
  3397. In-Reply-To: Your message of "Tue, 23 Feb 93 06:50:21 PST."
  3398.              <9302231450.AA04624@radium.sni.CA> 
  3399. Date:     Tue, 23 Feb 1993 09:22:30 PST
  3400. From: Fraser@europarc.xerox.com
  3401.  
  3402.  
  3403. For what it's worth, I have this at the start of a couple of my programs:
  3404.  
  3405. # This little bit of code helps find a module which isn't
  3406. # in the usual place! It adds the directory part of ARGV[0]
  3407. # and the standard unix path to the module search path.
  3408.  
  3409. rundir = posixpath.split(sys.argv[0])[0]
  3410. if rundir != '':
  3411.     sys.path.insert(0,rundir)
  3412. sys.path = sys.path + string.splitfields(posix.environ['PATH'],':')
  3413.  
  3414. Crude, but generally effective. Not as complete as your suggestion, though.
  3415.  
  3416. Quentin
  3417.  
  3418. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3419. Quentin Stafford-Fraser         
  3420. Rank Xerox EuroPARC,            I wish I was a little bug
  3421. Cambridge, UK            With hairs all round my tummy    
  3422. Tel: +44 223 341529          I'd jump into a honey pot
  3423. Fax: +44 223 341510          And make my tummy gummy.
  3424. Fraser@europarc.xerox.com                   Ogden Nash
  3425. 
  3426. 
  3427. To: python-list
  3428. Subject: formatted output
  3429. From: Guido.van.Rossum@cwi.nl
  3430. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  3431. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3432. Date: Mon, 08 Mar 1993 15:00:52 +0100
  3433. Sender: guido
  3434.  
  3435. As you all know, formatted output isn't currently among Python's
  3436. strong points.  Here's an idea to fix it.  Comments, please!
  3437.  
  3438. - The binary operator '%' is overloaded with a new meaning: if its
  3439. left argument is a string, the right argument can be any value, and
  3440. the result is a string.
  3441.  
  3442. - The outcome of "s % v" is informally defined as the string resulting
  3443. from "sprintf(buf, s, v)" in C.
  3444.  
  3445. - The outcome of "s % (v1, v2, ...)" is similarly defined as the
  3446. result of "sprintf(buf, s, v1, v2, ...)".
  3447.  
  3448. The net effect is that you can do things like
  3449.  
  3450. >>> print '/%6d/%6g/%-6s/' % (300, 3.14, 'x')
  3451. /   300/  3.14/x     /
  3452. >>>
  3453.  
  3454. But also
  3455.  
  3456. >>> s = '/%6d/%6g/%-6s/' % (300, 3.14, 'x')
  3457. >>> print s
  3458. '/   300/  3.14/x     /'
  3459. >>>
  3460.  
  3461. Complete error checking will of course ensure that mismatches between
  3462. the format and the supplied values will raise exceptions rather than
  3463. dump core or yield garbage.  Possibly the range of values accepted by
  3464. certain format codes will be richer than for C, e.g. %f and %g will
  3465. work with integers, and some format codes will be identical, e.g. %hd,
  3466. %d and %ld should make no difference.  Arbitrary values can be
  3467. formatted using '%s' % `value`.  (That's reverse quotes around value.)
  3468.  
  3469. I hope this concise description conveys my ideas (which are less than
  3470. half an hour old at the moment I am writing this) sufficiently.
  3471. Please send in your suggestions for alternatives!
  3472.  
  3473. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3474.  
  3475. PS. I'm sorry for not responding to some earlier messages, e.g. about
  3476. program structure -- the issues raised there are certainly
  3477. interesting, I'm just incredibly busy...
  3478. 
  3479. 
  3480. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3481.     id AA12764 (5.65b/3.8/CWI-Amsterdam); Mon, 8 Mar 1993 15:00:56 +0100
  3482. Received: by voorn.cwi.nl with SMTP
  3483.     id AA18613 (5.65b/3.8/CWI-Amsterdam); Mon, 8 Mar 1993 15:00:53 +0100
  3484. Message-Id: <9303081400.AA18613=guido@voorn.cwi.nl>
  3485. To: python-list@cwi.nl
  3486. Subject: formatted output
  3487. From: Guido.van.Rossum@cwi.nl
  3488. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  3489. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3490. Date: Mon, 08 Mar 1993 15:00:52 +0100
  3491. Sender: Guido.van.Rossum@cwi.nl
  3492.  
  3493. As you all know, formatted output isn't currently among Python's
  3494. strong points.  Here's an idea to fix it.  Comments, please!
  3495.  
  3496. - The binary operator '%' is overloaded with a new meaning: if its
  3497. left argument is a string, the right argument can be any value, and
  3498. the result is a string.
  3499.  
  3500. - The outcome of "s % v" is informally defined as the string resulting
  3501. from "sprintf(buf, s, v)" in C.
  3502.  
  3503. - The outcome of "s % (v1, v2, ...)" is similarly defined as the
  3504. result of "sprintf(buf, s, v1, v2, ...)".
  3505.  
  3506. The net effect is that you can do things like
  3507.  
  3508. >>> print '/%6d/%6g/%-6s/' % (300, 3.14, 'x')
  3509. /   300/  3.14/x     /
  3510. >>>
  3511.  
  3512. But also
  3513.  
  3514. >>> s = '/%6d/%6g/%-6s/' % (300, 3.14, 'x')
  3515. >>> print s
  3516. '/   300/  3.14/x     /'
  3517. >>>
  3518.  
  3519. Complete error checking will of course ensure that mismatches between
  3520. the format and the supplied values will raise exceptions rather than
  3521. dump core or yield garbage.  Possibly the range of values accepted by
  3522. certain format codes will be richer than for C, e.g. %f and %g will
  3523. work with integers, and some format codes will be identical, e.g. %hd,
  3524. %d and %ld should make no difference.  Arbitrary values can be
  3525. formatted using '%s' % `value`.  (That's reverse quotes around value.)
  3526.  
  3527. I hope this concise description conveys my ideas (which are less than
  3528. half an hour old at the moment I am writing this) sufficiently.
  3529. Please send in your suggestions for alternatives!
  3530.  
  3531. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3532.  
  3533. PS. I'm sorry for not responding to some earlier messages, e.g. about
  3534. program structure -- the issues raised there are certainly
  3535. interesting, I'm just incredibly busy...
  3536. 
  3537. 
  3538. Replied: Thu, 11 Mar 1993 19:40:38 +0100
  3539. Replied: "peter@robots.oxford.ac.uk python-list"
  3540. Received: from relay.surfnet.nl by charon.cwi.nl with SMTP
  3541.     id AA10722 (5.65b/3.8/CWI-Amsterdam); Wed, 10 Mar 1993 20:12:46 +0100
  3542. X400-Received: by mta relay.surfnet.nl in /PRMD=surf/ADMD=400net/C=nl/; Relayed;
  3543.                Wed, 10 Mar 1993 20:12:42 +0100
  3544. X400-Received: by /PRMD=surf/ADMD=400net/C=nl/; Relayed;
  3545.                Wed, 10 Mar 1993 20:13:30 +0100
  3546. X400-Received: by /PRMD=uk.ac/ADMD= /C=gb/; Relayed;
  3547.                Wed, 10 Mar 1993 20:12:02 +0100
  3548. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  3549.                Wed, 10 Mar 1993 20:12:07 +0100
  3550. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  3551.                Wed, 10 Mar 1993 20:12:04 +0100
  3552. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  3553.                Wed, 10 Mar 1993 20:12:04 +0100
  3554. Date: Wed, 10 Mar 1993 20:12:04 +0100
  3555. X400-Originator: peter%robots.oxford.ac.uk@prg.oxford.ac.uk
  3556. X400-Recipients: python-list@cwi.nl
  3557. X400-Mts-Identifier: [/PRMD=UK.AC/ADMD= /C=GB/;<9303101912.AA19607@thurio.robot]
  3558. X400-Content-Type: P2-1984 (2)
  3559. Content-Identifier: Matrix Module
  3560. From: peter@robots.oxford.ac.uk
  3561. Message-Id: <9303101912.AA19607@thurio.robots.ox.ac.uk>
  3562. To: python-list@cwi.nl
  3563. Subject: Matrix Module
  3564.  
  3565. Hi,
  3566.     I'm thinking of doing some prototyping work which involve 
  3567. matrices, has anyone written a C or python module that allows 
  3568. the usual operations.  If not, I'll have to use C :-(
  3569.  
  3570. Thanks,
  3571.     Pete.
  3572. 
  3573. 
  3574. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3575.     id AA24035 (5.65b/3.8/CWI-Amsterdam); Thu, 11 Mar 1993 19:40:39 +0100
  3576. Received: by voorn.cwi.nl with SMTP
  3577.     id AA27929 (5.65b/3.8/CWI-Amsterdam); Thu, 11 Mar 1993 19:40:38 +0100
  3578. Message-Id: <9303111840.AA27929=guido@voorn.cwi.nl>
  3579. To: peter@robots.oxford.ac.uk
  3580. Cc: python-list@cwi.nl
  3581. Subject: Re: Matrix Module 
  3582. In-Reply-To: Your message of "Wed, 10 Mar 1993 20:12:04 MET."
  3583.              <9303101912.AA19607@thurio.robots.ox.ac.uk> 
  3584. From: Guido.van.Rossum@cwi.nl
  3585. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  3586. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  3587. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3588. Date: Thu, 11 Mar 1993 19:40:38 +0100
  3589. Sender: Guido.van.Rossum@cwi.nl
  3590.  
  3591. >    I'm thinking of doing some prototyping work which involve 
  3592. >matrices, has anyone written a C or python module that allows 
  3593. >the usual operations.  If not, I'll have to use C :-(
  3594.  
  3595. I have a generalized array module (in C) that would store large
  3596. arrays/matrices of floats quite a bit more efficiently than Python
  3597. lists.  I have also written a generalized N-dimensional array module
  3598. (in Python) that you can use with the array module or with ordinary
  3599. lists to implement matrix ops.  The latter is really still under
  3600. development.  I should also warn you that "the usual ops on matrices"
  3601. is a very ambiguous statement, if you need numerical operations like
  3602. inversion you're out of luck.  I wouldn't dream of writing numerical
  3603. code in Python; nor would I dream of writing it in C; I would just
  3604. link to an existing numerical library...
  3605.  
  3606. Cheers,
  3607.  
  3608. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3609.  
  3610. 
  3611. 
  3612. Replied: Fri, 12 Mar 1993 13:30:36 +0100
  3613. Replied: "Mats.Lidell@eua.ericsson.se (Mats Lidell) "
  3614. Received: from mailgate.ericsson.se by charon.cwi.nl with SMTP
  3615.     id AA05854 (5.65b/3.8/CWI-Amsterdam); Fri, 12 Mar 1993 11:41:00 +0100
  3616. Received: from eua.ericsson.se by mailgate.ericsson.se (4.1/SMI-4.1-MAILGATE1.12)
  3617.     id AA25951; Fri, 12 Mar 93 11:40:56 +0100
  3618. Received: from ms.eua.ericsson.se by eua.ericsson.se (4.1/EUA-2.1)
  3619.     id AA11856; Fri, 12 Mar 93 11:40:55 +0100
  3620. Received: from euas66c31.eua.ericsson.se by ms.eua.ericsson.se (4.1/MS-2.1)
  3621.     id AA04729; Fri, 12 Mar 93 11:40:54 +0100
  3622. From: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  3623. Received: by euas66c31.eua.ericsson.se (4.1/client-1.3)
  3624.     id AA01151; Fri, 12 Mar 93 11:40:54 +0100
  3625. Date: Fri, 12 Mar 93 11:40:54 +0100
  3626. Message-Id: <9303121040.AA01151@euas66c31.eua.ericsson.se>
  3627. To: python-list@cwi.nl
  3628. Subject: Python and stdwin port to the Amiga?
  3629. Comments: Hyperbole mail buttons accepted, v3.06.
  3630.  
  3631. Hi Folks,
  3632.  
  3633. Is there a port or is anyone planning to port python and/or stdwin to
  3634. the Amiga?
  3635.  
  3636. %% Mats
  3637. 
  3638. 
  3639. To: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  3640. Subject: Re: Python and stdwin port to the Amiga? 
  3641. In-reply-to: Your message of "Fri, 12 Mar 1993 11:40:54 MET."
  3642.              <9303121040.AA01151@euas66c31.eua.ericsson.se> 
  3643. From: Guido.van.Rossum@cwi.nl
  3644. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  3645. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  3646. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3647. Date: Fri, 12 Mar 1993 13:30:36 +0100
  3648. Sender: guido
  3649.  
  3650. >Is there a port or is anyone planning to port python and/or stdwin to
  3651. >the Amiga?
  3652.  
  3653. Porting Python (at least the core interpreter) should be a matter of
  3654. having a decent C compiler.  It is very portable code, for the most
  3655. part (having been developed in part on a Mac with 16-bit ints), except
  3656. the inherently OS-dependent parts like posixmodule.c (which is
  3657. optional anyway).
  3658.  
  3659. Porting STDWIN would require serious knowledge of the Amiga window
  3660. system, you would have to write most code from scratch.  I haven't
  3661. heard of anyone attempting this yet.
  3662.  
  3663. Cheers,
  3664.  
  3665. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3666. 
  3667. 
  3668. Replied: Sat, 13 Mar 1993 12:01:41 +0100
  3669. Replied: "Ty Sarna <tsarna@endicor.com> "
  3670. Received: from dptspd.sat.datapoint.com by charon.cwi.nl with SMTP
  3671.     id AA03773 (5.65b/3.8/CWI-Amsterdam); Sat, 13 Mar 1993 01:10:25 +0100
  3672. Received: from fezzik.endicor.com by dptspd.sat.datapoint.com with uucp
  3673.     (Smail3.1.28.1 #2) id m0nXJrN-000196C; Fri, 12 Mar 93 18:13 CST
  3674. Received: by fezzik.endicor.com (TMA-1/EndiNet)
  3675.     id AA04135; Fri, 12 Mar 1993 17:50:39 CST
  3676. Message-Id: <1993Mar12.175039.04135@fezzik.endicor.com>
  3677. Date: Fri, 12 Mar 1993 17:50:39 CST
  3678. Organization: Endicor Technologies, Inc., San Antonio, Texas
  3679. From: Ty Sarna <tsarna@endicor.com>
  3680. Subject: Re:  Python and stdwin port to the Amiga?
  3681. To: Mats.Lidell@eua.ericsson.se, python-list@cwi.nl
  3682.  
  3683. > Hi Folks,
  3684. > Is there a port or is anyone planning to port python and/or stdwin to
  3685. > the Amiga?
  3686.  
  3687. A straight port is pretty easy, but to really be useful, the python
  3688. interpreter needs to be in a .library and needs to be able to able to
  3689. import other modules in .library's as ARexx does. This quickly get's
  3690. complicated -- Python's implementation just doesn't fit well on the
  3691. Amiga. Things like calling exit() from inside a shared library are a
  3692. pain. I hacked on it some before DevCon but I've been very busy since
  3693. and have half given up. If someone gets a nice port done I'd love to see
  3694. it though. 
  3695.  
  3696. Lately I've been toying with ideas for a semi-pythonesque compiled
  3697. language aimed particularly at high-performance concurrent
  3698. network-distributed OO programming. 
  3699.  
  3700. --
  3701. Ty Sarna           "Never let your sense of morals prevent you from
  3702. tsarna@endicor.com    doing what's right" -- Salvor Hardin
  3703. 
  3704. 
  3705. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3706.     id AA24210 (5.65b/3.8/CWI-Amsterdam); Thu, 18 Mar 1993 16:49:19 +0100
  3707. Received: by voorn.cwi.nl with SMTP
  3708.     id AA28866 (5.65b/3.8/CWI-Amsterdam); Thu, 18 Mar 1993 16:49:19 +0100
  3709. Message-Id: <9303181549.AA28866=guido@voorn.cwi.nl>
  3710. To: python-list@cwi.nl
  3711. Subject: MS-DOS executable available
  3712. From: Guido.van.Rossum@cwi.nl
  3713. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  3714. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3715. Date: Thu, 18 Mar 1993 16:49:18 +0100
  3716. Sender: Guido.van.Rossum@cwi.nl
  3717.  
  3718. An MS-DOS executable of Python 0.9.8 is now available for anonymous
  3719. from host ftp.cwi.nl, directory pub/python, file python.exe.Z.  The
  3720. file is compressed with UNIX compress.  Use binary ftp transfer mode,
  3721. as always.  If you wait a couple of days, I hope this will be mirrored
  3722. at the usual places (e.g. gatekeeper, uunet).
  3723.  
  3724. Note that I can't really test this (although I've verified that it
  3725. at least starts up correctly), but if you find any problems with it
  3726. I'll try to forward them to the nice guy who built it for me.  I'll
  3727. keep the list informed on important known bugs.
  3728.  
  3729. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3730. 
  3731. 
  3732. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3733.     id AA22618 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 13:13:05 +0100
  3734. Received: by voorn.cwi.nl with SMTP
  3735.     id AA08412 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 13:13:05 +0100
  3736. Message-Id: <9303261213.AA08412=guido@voorn.cwi.nl>
  3737. To: python-list@cwi.nl
  3738. Subject: Mutable objects as mapping keys
  3739. From: Guido.van.Rossum@cwi.nl
  3740. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  3741. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3742. Date: Fri, 26 Mar 1993 13:13:04 +0100
  3743. Sender: Guido.van.Rossum@cwi.nl
  3744.  
  3745. It's mighty quiet on the python mailing list these days, so I suppose
  3746. you are all busy writing Python scripts for the next obfuscated Python
  3747. competition :-)
  3748.  
  3749. Seriously, I have a design problem.  I'm (at last!) writing code that
  3750. will support arbitrary values as keys for dictionaties.  So you will
  3751. at last be able to create a dictionary with numeric keys, or with
  3752. tuples containing strings and numbers, etc.  However, there's a
  3753. problem with allowing lists!  Since a list can be modified, its value
  3754. can be changed later.  E.g. if I create a list a = [1, 2] and use it
  3755. as a dictionary key, e.g. d = {a: 'foobar'}, and now I call
  3756. a.append(3), then the dictionary object is in trouble: it has saved a
  3757. *pointer* to a as the key, so the value of d has suddenly changed to
  3758. {[1, 2, 3]: 'foobar'}.  This is not what you want!  (I think :-)
  3759. Moreover, the dictionary implementation uses hashing of the keys, and
  3760. the entry will still be located at the hash value for [1, 2].
  3761.  
  3762. One way out seems to be to make a deep copy of the key value (if it
  3763. contains a mutable object), but this is slow.  You also have to make
  3764. another deep copy when the caller asks for the keys() of the
  3765. dictionary, otherwise there would still be a way to subvert the value
  3766. of a key...  Also note that there may be a list hidden deep inside a
  3767. tuple of tuples, so at least some of the the deep copying overhead is
  3768. present even when no lists are actually used as keys!
  3769.  
  3770. My current solution is to disallow mutable objects as dictionary keys,
  3771. unless object comparison is defined as pointer comparison for that
  3772. particular object (e.g. files).  This makes dictionaries less general,
  3773. since lists (or dictionaries!) can't be used as keys.  I can imagine
  3774. that this is sometimes a drag, but I don't think the performance
  3775. penalty of copying is acceptable, nor do I trust the users of
  3776. dictionaries never to accidentally modify a list they have used as a
  3777. key.
  3778.  
  3779. My questions to the general public are:
  3780.  
  3781. (1) do you think that disallowing lists as keys is a big drawback?
  3782.  
  3783. (2) would you accept the performance penalty of always deep copying
  3784. lists used as keys?  (2a) when using lists (2b) when not using lists!
  3785.  
  3786. (3) do you happen to have another implementation idea?
  3787.  
  3788. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3789. 
  3790. 
  3791. Replied: Fri, 26 Mar 1993 14:29:08 +0100
  3792. Replied: ""Clint Jeffery" <cjeffery@cs.arizona.edu> python-list"
  3793. Received: from optima.cs.arizona.edu by charon.cwi.nl with SMTP
  3794.     id AA23902 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 14:20:41 +0100
  3795. Received: from chuckwalla.cs.arizona.edu by optima.cs.arizona.edu (5.65c/15) via SMTP
  3796.     id AA29567; Fri, 26 Mar 1993 06:20:38 MST
  3797. Date: Fri, 26 Mar 1993 06:20:37 MST
  3798. From: "Clint Jeffery" <cjeffery@cs.arizona.edu>
  3799. Message-Id: <199303261320.AA29722@chuckwalla.cs.arizona.edu>
  3800. Received: by chuckwalla.cs.arizona.edu; Fri, 26 Mar 1993 06:20:37 MST
  3801. To: Guido.van.Rossum@cwi.nl
  3802. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Fri, 26 Mar 1993 13:13:04 +0100 <9303261213.AA08412=guido@voorn.cwi.nl>
  3803. Subject: Mutable objects as mapping keys
  3804.  
  3805.    (1) do you think that disallowing lists as keys is a big drawback?
  3806.  
  3807. Its not a practical drawback, it is merely a drawback in "elegance".
  3808. It seems cleaner to do this than to do the deep copy thing though.
  3809.  
  3810.    (2) would you accept the performance penalty of always deep copying
  3811.    lists used as keys?  (2a) when using lists (2b) when not using lists!
  3812.  
  3813. How deep?  Does Python allow cycles in such structures?
  3814.  
  3815.    (3) do you happen to have another implementation idea?
  3816.  
  3817. Icon allows structure keys, and such keys can change -- lists have an
  3818. associated serial number that is used for hashing since neither the
  3819. contents nor the pointer to the list are safe to hash on.  It is fast,
  3820. cheap, and consistent with the mutable nature of (Icon) lists...but
  3821. maybe Python lists are qualitatively different than Icon lists.
  3822. 
  3823. 
  3824. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  3825.     id AA24171 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 14:29:09 +0100
  3826. Received: by voorn.cwi.nl with SMTP
  3827.     id AA08971 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 14:29:08 +0100
  3828. Message-Id: <9303261329.AA08971=guido@voorn.cwi.nl>
  3829. To: "Clint Jeffery" <cjeffery@cs.arizona.edu>
  3830. Cc: python-list@cwi.nl
  3831. Subject: Re: Mutable objects as mapping keys 
  3832. In-Reply-To: Your message of "Fri, 26 Mar 1993 06:20:37 MET."
  3833.              <199303261320.AA29722@chuckwalla.cs.arizona.edu> 
  3834. From: Guido.van.Rossum@cwi.nl
  3835. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  3836. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  3837. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  3838. Date: Fri, 26 Mar 1993 14:29:08 +0100
  3839. Sender: Guido.van.Rossum@cwi.nl
  3840.  
  3841. "Clint Jeffery" <cjeffery@cs.arizona.edu> writes:
  3842.  
  3843. >   (1) do you think that disallowing lists as keys is a big drawback?
  3844. >
  3845. >Its not a practical drawback, it is merely a drawback in "elegance".
  3846. >It seems cleaner to do this than to do the deep copy thing though.
  3847.  
  3848. That's what I though too.
  3849.  
  3850. >   (2) would you accept the performance penalty of always deep copying
  3851. >   lists used as keys?  (2a) when using lists (2b) when not using lists!
  3852. >
  3853. >How deep?  Does Python allow cycles in such structures?
  3854.  
  3855. Oops, you're right, it is possible to create lists containing circular
  3856. references.  This would make deep-copying even less practical.
  3857. (Circular references cause other problems too, e.g. can't be printed
  3858. or dumped through "marshal", but they can be useful nevertheless, and
  3859. checking would be problematic.)
  3860.  
  3861. >   (3) do you happen to have another implementation idea?
  3862. >
  3863. >Icon allows structure keys, and such keys can change -- lists have an
  3864. >associated serial number that is used for hashing since neither the
  3865. >contents nor the pointer to the list are safe to hash on.  It is fast,
  3866. >cheap, and consistent with the mutable nature of (Icon) lists...but
  3867. >maybe Python lists are qualitatively different than Icon lists.
  3868.  
  3869. In Python using the pointer as a hash value would be safe (since it
  3870. can't change), but this would make lists almost as useless keys: after
  3871.  
  3872.     d = {[1, 2]: 2; [1, 2, 3]: 3}
  3873.  
  3874. the test
  3875.  
  3876.     d.has_key([1, 2])
  3877.  
  3878. would yield false, since the [1, 2] used here is a different instance
  3879. than the [1, 2] used as key.
  3880.  
  3881. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  3882. 
  3883. 
  3884. Received: from inesc.inesc.pt by charon.cwi.nl with SMTP
  3885.     id AA25367 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 15:51:14 +0100
  3886. Received: from sabrina-2.inesc.pt by inesc.inesc.pt with SMTP;
  3887.     id AA09018 (5.65a/Ultrix4.0); Fri, 26 Mar 93 15:51:35 +0100
  3888. Received: from cretina.inesc.pt by sabrina.inesc.pt (4.1/SunOS4.1.1)
  3889.     id AA07401; Fri, 26 Mar 93 15:50:48 +0100
  3890. Date: Fri, 26 Mar 93 15:50:48 +0100
  3891. From: pereira@sabrina.inesc.pt (Jose M. Pereira)
  3892. Message-Id: <9303261450.AA07401@sabrina.inesc.pt>
  3893. Received: by cretina.inesc.pt (4.1/SMI-4.1)
  3894.     id AA04230; Fri, 26 Mar 93 15:50:45 +0100
  3895. To: Guido.van.Rossum@cwi.nl
  3896. Cc: python-list@cwi.nl
  3897. Subject: Mutable objects as mapping keys
  3898. In-Reply-To: <9303261213.AA08412=guido@voorn.cwi.nl>
  3899. References: <9303261213.AA08412=guido@voorn.cwi.nl>
  3900.  
  3901. Guido van Rossum writes:
  3902. > My questions to the general public are:
  3903. > (1) do you think that disallowing lists as keys is a big drawback?
  3904.  
  3905. Not really. I can't even think of an obvious example where it would be
  3906. useful...
  3907.  
  3908. > (2) would you accept the performance penalty of always deep copying
  3909. > lists used as keys?  (2a) when using lists (2b) when not using
  3910. > lists!
  3911.  
  3912. One of the biggest advantages of using dictionaries is the efficiency
  3913. of search (hash tables, etc...). So, I would say no at least in case (2b).
  3914.  
  3915. > (3) do you happen to have another implementation idea?
  3916.  
  3917. Unfortunately, I must throw another "no" in here...
  3918.  
  3919. ----------------------------------------------------------------------
  3920. Jose' Pereira
  3921.  
  3922.  
  3923.          INESC (Inst. Eng. Sistemas e Computadores)
  3924.              R. Alves Redol 9, 6. 1000 Lisboa, PORTUGAL.
  3925.              Phone.: +351 1 3100225 Fax...: +351 1 525843
  3926.     e-mail: jmp@inesc.pt  PSI...: %(0268)004010314::inesc::jmp
  3927.  
  3928. 
  3929. 
  3930. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  3931.     id AA29485 (5.65b/3.8/CWI-Amsterdam); Fri, 26 Mar 1993 19:06:06 +0100
  3932. Received: from server.cs.virginia.edu by uvaarpa.virginia.edu id aa15864;
  3933.           26 Mar 93 12:23 EST
  3934. Received: from bodhi.cs.Virginia.EDU by uvacs.cs.virginia.edu (4.1/5.1.UVA)
  3935.     id AA03321; Fri, 26 Mar 93 12:23:12 EST
  3936. Posted-Date: Fri, 26 Mar 93 12:23:11 EST
  3937. Return-Path: <kph2q@bodhi.cs.Virginia.EDU>
  3938. Received: by bodhi.cs.Virginia.EDU (4.1/SMI-2.0)
  3939.     id AA11832; Fri, 26 Mar 93 12:23:11 EST
  3940. Date: Fri, 26 Mar 93 12:23:11 EST
  3941. From: Kenneth Hinckley <kph2q@bodhi.cs.virginia.edu>
  3942. Message-Id: <9303261723.AA11832@bodhi.cs.Virginia.EDU>
  3943. To: Guido.van.Rossum@cwi.nl
  3944. Subject: Re: Mutable objects as mapping keys
  3945. References: <9303261213.AA08412=guido@voorn.cwi.nl>
  3946.  
  3947.  
  3948. Guido.van.Rossum@cwi.nl writes:
  3949.  
  3950.   | My questions to the general public are:
  3951.  
  3952.   | (1) do you think that disallowing lists as keys is a big drawback?
  3953. No, especially since having lists as keys is likely to be (1)
  3954. confusing to the programmer and (2) a probable source of bugs or
  3955. undesirable interactions with other language features.
  3956.  
  3957.   | (2) would you accept the performance penalty of always deep copying
  3958.   | lists used as keys?  (2a) when using lists (2b) when not using lists!
  3959. (2a) Yes
  3960. (2b) Absolutely not!  Using lists as keys is probably handy about one
  3961. time out of a hundred, and the other 99 times you shouldn't have to
  3962. pay for the cost.
  3963.  
  3964.   | (3) do you happen to have another implementation idea?
  3965. You might consider having an immutable list type, i.e. a list that
  3966. doesn't support .append(), etc.  Of course, now you have the problem
  3967. of specifying whether a given list is mutable or immutable; python's
  3968. aversion to static type declarations might make this idea impractical. 
  3969.  
  3970. Perhaps another way to approach it would be to have a .lock() method
  3971. for lists.  When a list is 'locked', it is immutable-- trying to call
  3972. a method that changes the list would raise an exception.  Trying to
  3973. place an unlocked list in a dictionary would also raise an exception.
  3974.  
  3975.  
  3976. Hope some of this is vaguely useful.
  3977.  
  3978. Ken
  3979.  
  3980. 
  3981. 
  3982. Replied: Sat, 27 Mar 1993 10:16:11 +0100
  3983. Replied: "manny@tcomeng.com (Manny Juan) "
  3984. Received: from tcomeng.com by charon.cwi.nl with SMTP
  3985.     id AA05354 (5.65b/3.8/CWI-Amsterdam); Sat, 27 Mar 1993 08:47:28 +0100
  3986. Received: by tcomeng.com (AIX 3.2/UCB 5.64/4.03)
  3987.           id AA58290; Fri, 26 Mar 1993 23:45:08 -0800
  3988. From: manny@tcomeng.com (Manny Juan)
  3989. Message-Id: <9303270745.AA58290@tcomeng.com>
  3990. Subject: python (msdos) docs? libraries?
  3991. To: python-list@cwi.nl
  3992. Date: Fri, 26 Mar 1993 23:45:08 -0800 (PST)
  3993. X-Mailer: ELM [version 2.4 PL21]
  3994. Mime-Version: 1.0
  3995. Content-Type: text/plain; charset=US-ASCII
  3996. Content-Transfer-Encoding: 7bit
  3997. Content-Length: 188       
  3998.  
  3999. where can i find the following? (in ascii)
  4000.  
  4001. tutorial for python for ms-dos
  4002. docs / language ref for ms-dos
  4003. libraries/modules/support files for python for ms-dos
  4004.  
  4005. thanks
  4006.  
  4007. manny@tcomeng.COM
  4008.  
  4009. 
  4010. 
  4011. To: manny@tcomeng.com (Manny Juan)
  4012. Subject: Re: python (msdos) docs? libraries? 
  4013. In-reply-to: Your message of "Fri, 26 Mar 1993 23:45:08 MET."
  4014.              <9303270745.AA58290@tcomeng.com> 
  4015. From: Guido.van.Rossum@cwi.nl
  4016. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  4017. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  4018. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4019. Date: Sat, 27 Mar 1993 10:16:12 +0100
  4020. Sender: guido
  4021.  
  4022. >where can i find the following? (in ascii)
  4023. >
  4024. >tutorial for python for ms-dos
  4025. >docs / language ref for ms-dos
  4026. >libraries/modules/support files for python for ms-dos
  4027.  
  4028. You will have to ftp the UNIX source distribution and extract them
  4029. from there.  The variable sys.builtin_module_names lists the built-in
  4030. modules -- this will tell you which parts of the library reference to
  4031. skip.
  4032.  
  4033. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4034. 
  4035. 
  4036. Replied: Mon, 29 Mar 1993 18:36:04 +0100
  4037. Replied: "Tim Peters <tim@ksr.com> python-list@cwi.nl"
  4038. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  4039.     id AA02812 (5.65b/3.8/CWI-Amsterdam); Mon, 29 Mar 1993 05:24:53 +0100
  4040. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  4041.     id AA23011; Sun, 28 Mar 1993 23:24:41 -0500
  4042. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  4043.     id AA11299; Sun, 28 Mar 93 23:25:04 EST
  4044. Received: by kaos.ksr.com (4.1/KSR-2.0)
  4045.     id AA28662; Sun, 28 Mar 93 23:25:02 EST
  4046. Message-Id: <9303290425.AA28662@kaos.ksr.com>
  4047. To: python-list@cwi.nl
  4048. Subject: Re: Mutable objects as mapping keys
  4049. Date: Sun, 28 Mar 93 23:24:56 EST
  4050. From: Tim Peters <tim@ksr.com>
  4051.  
  4052. > if I create a list a = [1, 2] and use it as a dictionary key, e.g. d =
  4053. > {a: 'foobar'}, and now I call a.append(3), then the dictionary object
  4054. > is in trouble: it has saved a *pointer* to a as the key, so the value
  4055. > of d has suddenly changed to {[1, 2, 3]: 'foobar'}.  This is not what
  4056. > you want!  (I think :-)
  4057.  
  4058. Well, _I_ can live with that <smile>.  In fact, if I think of a
  4059. dictionary as mapping _objects_ to objects, this is the behavior I
  4060. expect, since a.append(3) doesn't change a's identity _as an object_.
  4061. It's only confusing if I think of a dictionary as mapping _values_ to
  4062. objects.  Both views can be useful, & I suspect the best thing to do is
  4063. to compromise:
  4064.  
  4065. > ...
  4066. > In Python using the pointer as a hash value would be safe (since it
  4067. > can't change), but this would make lists almost useless as keys: after
  4068. >
  4069. >     d = {[1, 2]: 2; [1, 2, 3]: 3}
  4070. >
  4071. > the test
  4072. >
  4073. >     d.has_key([1, 2])
  4074. >
  4075. > would yield false, since the [1, 2] used here is a different instance
  4076. > than the [1, 2] used as key.
  4077.  
  4078. The same is true in Icon, where "dictionaries" are called "tables", and
  4079. can be indexed by anything (strings, lists, other tables, pieces of code,
  4080. ... anything).  E.g.,
  4081.  
  4082. kaos 36= cat t.icn
  4083. procedure main()
  4084.    local t, x
  4085.    t := table()  # a table, mapping anything to anything
  4086.    x := [1,2]     # a list
  4087.    t[x] := 5
  4088.    if /t[x] then write( "x not in table" )
  4089.         else write( "x associated with ", t[x] )
  4090.    push( x, 3 )  # x becomes [1,2,3]
  4091.    if /t[x] then write( "x not in table" )
  4092.         else write( "x associated with ", t[x] )
  4093.    x := [1,2,3]  # same _value_ as x, but different object
  4094.    if /t[x] then write( "x not in table" )
  4095.         else write( "x associated with ", t[x] )
  4096. end
  4097. kaos 37= it -s t -x
  4098. x associated with 5
  4099. x associated with 5
  4100. x not in table
  4101. kaos 38=
  4102.  
  4103. This doesn't stop Icon's tables from being useful.  E.g., the Icon
  4104. Program Library uses this feature many times, especially in routines to
  4105. provide printable representations for arbitrary (including cyclic) data
  4106. structures.  In fact, "pointer equality" semantics for structured objects
  4107. are crucial to making that kind of routine easy to write.  I can't
  4108. remember the specifics now, but I know that in Icon I once even had a
  4109. "good use" for a table that was itself indexed by tables (some hairy
  4110. graph algorithm ... and again it was crucial that the mapping not be
  4111. affected by changes _to_ the tables used as indices).
  4112.  
  4113. The best approach is probably a philosophical mix:  use "value equality"
  4114. for an index with type string or number or Null, and "object equality"
  4115. for everything else (I guess Null fits in either branch).  The
  4116. distinction here is best viewed as being between, say, "atomic objects"
  4117. (those like numbers & strings with no internally visible structure) and
  4118. "structured objects" (those, like lists & tuples, built out of simpler
  4119. types).  Probably best if d[2] and d[2L] and d[2.0] mapped to different
  4120. things too (so that "value equality" is sensitive to type as well as to
  4121. value).
  4122.  
  4123. I think I just recast Icon's rules into Pythonese there.  It's a pretty
  4124. good way to go in practice, & I really don't know of a better one.
  4125.  
  4126. Perl carries value equality to an extreme, so that after
  4127.     $dict{1} = 'hi';
  4128. $dict{1} and $dict{'1'} and $dict{cos(0.0)} all refer to 'hi' too.
  4129. _That_ can be surprising.
  4130.  
  4131. thinking-this-is-one-of-those-happy-cases-where-the-easiest-implementation-
  4132.    is-also-the-most-efficient-&-the-most-useful-ly y'rs  - tim
  4133.  
  4134. Tim Peters   tim@ksr.com
  4135. not speaking for Kendall Square Research Corp
  4136. 
  4137. 
  4138. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  4139.     id AA12375 (5.65b/3.8/CWI-Amsterdam); Mon, 29 Mar 1993 12:28:05 +0100
  4140. Received: by voorn.cwi.nl with SMTP
  4141.     id AA16226 (5.65b/3.8/CWI-Amsterdam); Mon, 29 Mar 1993 12:28:04 +0100
  4142. Message-Id: <9303291128.AA16226=guido@voorn.cwi.nl>
  4143. To: python-list@cwi.nl
  4144. Subject: tzparse.py
  4145. From: Guido.van.Rossum@cwi.nl
  4146. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  4147. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4148. Date: Mon, 29 Mar 1993 12:28:04 +0100
  4149. Sender: Guido.van.Rossum@cwi.nl
  4150.  
  4151. Now daylight saving time has arrived (at least in Europe), I've
  4152. discovered a bug in tzparse.py.  Please apply this patch if your
  4153. "mclock" is now running two hours behind:
  4154.  
  4155. ===================================================================
  4156. RCS file: /ufs/guido/CVSROOT/python/lib/tzparse.py,v
  4157. retrieving revision 1.1
  4158. diff -c -1 -r1.1 tzparse.py
  4159. *** 1.1    1992/10/18 17:09:58
  4160. --- tzparse.py    1993/03/29 11:23:50
  4161. ***************
  4162. *** 42,44 ****
  4163.       timezone = tzparams[1] * 3600
  4164. !     altzone = timezone + 3600
  4165.       daylight = 1
  4166. --- 42,44 ----
  4167.       timezone = tzparams[1] * 3600
  4168. !     altzone = timezone - 3600
  4169.       daylight = 1
  4170.  
  4171.  
  4172. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4173. 
  4174. 
  4175. To: python-list
  4176. Subject: tzparse.py
  4177. From: Guido.van.Rossum@cwi.nl
  4178. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  4179. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4180. Date: Mon, 29 Mar 1993 12:28:04 +0100
  4181. Sender: guido
  4182.  
  4183. Now daylight saving time has arrived (at least in Europe), I've
  4184. discovered a bug in tzparse.py.  Please apply this patch if your
  4185. "mclock" is now running two hours behind:
  4186.  
  4187. ===================================================================
  4188. RCS file: /ufs/guido/CVSROOT/python/lib/tzparse.py,v
  4189. retrieving revision 1.1
  4190. diff -c -1 -r1.1 tzparse.py
  4191. *** 1.1    1992/10/18 17:09:58
  4192. --- tzparse.py    1993/03/29 11:23:50
  4193. ***************
  4194. *** 42,44 ****
  4195.       timezone = tzparams[1] * 3600
  4196. !     altzone = timezone + 3600
  4197.       daylight = 1
  4198. --- 42,44 ----
  4199.       timezone = tzparams[1] * 3600
  4200. !     altzone = timezone - 3600
  4201.       daylight = 1
  4202.  
  4203.  
  4204. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4205. 
  4206. 
  4207. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  4208.     id AA09843 (5.65b/3.8/CWI-Amsterdam); Mon, 29 Mar 1993 19:36:06 +0200
  4209. Received: by voorn.cwi.nl with SMTP
  4210.     id AA17494 (5.65b/3.8/CWI-Amsterdam); Mon, 29 Mar 1993 18:36:05 +0100
  4211. Message-Id: <9303291736.AA17494=guido@voorn.cwi.nl>
  4212. To: Tim Peters <tim@ksr.com>
  4213. Cc: python-list@cwi.nl
  4214. Subject: Re: Mutable objects as mapping keys 
  4215. In-Reply-To: Your message of "Sun, 28 Mar 1993 23:24:56 MET."
  4216.              <9303290425.AA28662@kaos.ksr.com> 
  4217. From: Guido.van.Rossum@cwi.nl
  4218. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  4219. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  4220. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4221. Date: Mon, 29 Mar 1993 18:36:04 +0100
  4222. Sender: Guido.van.Rossum@cwi.nl
  4223.  
  4224. Tim Peters writes:
  4225.  
  4226. >Well, _I_ can live with that <smile>.  In fact, if I think of a
  4227. >dictionary as mapping _objects_ to objects, this is the behavior I
  4228. >expect, since a.append(3) doesn't change a's identity _as an object_.
  4229. >It's only confusing if I think of a dictionary as mapping _values_ to
  4230. >objects.  Both views can be useful, & I suspect the best thing to do is
  4231. >to compromise:
  4232. [Icon example deleted]
  4233. >The best approach is probably a philosophical mix:  use "value equality"
  4234. >for an index with type string or number or Null, and "object equality"
  4235. >for everything else (I guess Null fits in either branch).  The
  4236. >distinction here is best viewed as being between, say, "atomic objects"
  4237. >(those like numbers & strings with no internally visible structure) and
  4238. >"structured objects" (those, like lists & tuples, built out of simpler
  4239. >types).  Probably best if d[2] and d[2L] and d[2.0] mapped to different
  4240. >things too (so that "value equality" is sensitive to type as well as to
  4241. >value).
  4242. >
  4243. >I think I just recast Icon's rules into Pythonese there.  It's a pretty
  4244. >good way to go in practice, & I really don't know of a better one.
  4245.  
  4246. You seem to have a minority viewpoint here :-).  I would argue that in
  4247. Python, in most cases, value semantics are more useful.  The reason is
  4248. probably that value semantics abound elsewhere in Python: e.g. (x == y)
  4249. compares values, not object identities, and so does the test (x in y)
  4250. where y is a list: indeed (0 in [0.0]) is true.
  4251.  
  4252. This makes it unattractive to use object semantics for dictionary
  4253. keys, since it would break a useful invariant: if x in m.keys(),
  4254. m.has_key(x) is true and m[x] is uniquely defined.
  4255.  
  4256. In Python (I don't know about Icon) it is always possible to force
  4257. object semantics by wrapping a value in a class instance.  The reverse
  4258. is not true.
  4259.  
  4260. Since most opaque object types in Python have object semantics anyway
  4261. (e.g. if you open the same file twice, the open file objects compare
  4262. different), the only types for which choosing object or value
  4263. semantics makes a difference are tuples, lists and dictionaries (yes,
  4264. using dictionaries as keys can make sense -- e.g. when calculating
  4265. functions over graphs represented as dictionaries).
  4266.  
  4267. I strongly believe that tuples should be treated as values, not as
  4268. objects.  Consider a function of two arguments that is rather
  4269. expensive to calculate.  This function could maintain a dictionary of
  4270. previously calculated function values and return values from there if
  4271. available, like this:
  4272.  
  4273.     known = {}
  4274.     def f(a, b):
  4275.         if known.has_key((a,b)): return known[(a, b)]
  4276.         x = real_f(a, b)
  4277.         known[(a, b)] = x
  4278.         return x
  4279.  
  4280. This sounds like a useful general mechanism to have.  It also pleads
  4281. for identifying numerical keys which compare equal (not, of course,
  4282. taking it to the extreme that Perl does -- after all Python has a form
  4283. of strong typing), so f(1, 2) will reuse a known value for f(1.0, 2.0).
  4284.  
  4285. It is true that this doesn't work for your example of a library
  4286. routine that needs to be able to traverse *arbitrary* circular data
  4287. structures; but a built-in function returning the address of an object
  4288. as integer would be a good alternative (so you can still build a
  4289. dictionary keyed on object identity).
  4290.  
  4291. Regarding lists and dictionaries, the problem is this: if possible I
  4292. would like to support value semantics for those, but the
  4293. implementation makes this too difficult.  If I choose object
  4294. semantics, programs expecting value semantics (and exploiting the
  4295. invariants explained above) break unexpectedly.  Therefore I
  4296. choose (and have already implemented :-) not to support these types as
  4297. dictionary keys, so that at least the problem isn't obscured.
  4298.  
  4299. The whole exercise does point out a problem with value semantics for
  4300. mutable objects, but I still think Python uses a reasonable compromise
  4301. here, even if it is different from Icon's...
  4302.  
  4303. Thanks for reacting anyway,
  4304.  
  4305. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4306. 
  4307. 
  4308. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  4309.     id AA09825 (5.65b/3.8/CWI-Amsterdam); Tue, 30 Mar 1993 07:00:12 +0200
  4310. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  4311.     id AA13000; Mon, 29 Mar 1993 23:59:55 -0500
  4312. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  4313.     id AA21333; Tue, 30 Mar 93 00:00:19 EST
  4314. Received: by kaos.ksr.com (4.1/KSR-2.0)
  4315.     id AA15740; Tue, 30 Mar 93 00:00:11 EST
  4316. Message-Id: <9303300500.AA15740@kaos.ksr.com>
  4317. To: Guido.van.Rossum@cwi.nl
  4318. Subject: Re: Mutable objects as mapping keys
  4319. Cc: python-list@cwi.nl
  4320. Date: Tue, 30 Mar 93 00:00:10 EST
  4321. From: Tim Peters <tim@ksr.com>
  4322.  
  4323. > [guido]
  4324. > [much cogent explanation deleted, some reproduced below]
  4325. > ... but I still think Python uses a reasonable compromise here, even if
  4326. > it is different from Icon's...
  4327.  
  4328. I think it's reasonable too!  There are advantages to all these schemes.
  4329. I was particularly impressed by your arguments about the way "value
  4330. semantics" are used in other parts of Python, something I didn't
  4331. consider.  It is the case that Icon uses a specific mix of "value" and
  4332. "pointer" rules for dictionary resolution, but Icon also uses that same
  4333. mix of rules in its other comparison contexts (membership testing, its
  4334. "===" equality predicate, selecting which "case" clause applies).
  4335.  
  4336. On third thought I'm convinced this kind of consistency is worth more
  4337. than anything else.
  4338.  
  4339. > I strongly believe that tuples should be treated as values, not as
  4340. > objects.  Consider a function of two arguments that is rather
  4341. > expensive to calculate.  This function could maintain a dictionary of
  4342. > previously calculated function values and return values from there if
  4343. > available, like this:
  4344. >
  4345. >     known = {}
  4346. >     def f(a, b):
  4347. >         if known.has_key((a,b)): return known[(a, b)]
  4348. >         x = real_f(a, b)
  4349. >         known[(a, b)] = x
  4350. >         return x
  4351.  
  4352. Just noting that it's easy enough to fake given object semantics too.
  4353. E.g., assuming a & b are numbers & Python's dictionaries have been
  4354. extended to support indexing by numbers:
  4355.  
  4356.     known = {}
  4357.     def f(a,b):
  4358.         if known.has_key(a):
  4359.             a_vals = known[a]
  4360.             if a_vals.has_key(b): return a_vals[b]
  4361.         else:
  4362.             known[a] = a_vals = {}
  4363.         a_vals[b] = x = real_f(a, b)
  4364.         return x
  4365.  
  4366. For this probably-common kind of use, I sure agree that value semantics
  4367. allow a simpler solution (really, there's no need to trot out a function
  4368. with three arguments <grin>).
  4369.  
  4370. > ...
  4371. > It is true that this doesn't work for your example of a library
  4372. > routine that needs to be able to traverse *arbitrary* circular data
  4373. > structures; but a built-in function returning the address of an object
  4374. > as integer would be a good alternative (so you can still build a
  4375. > dictionary keyed on object identity).
  4376.  
  4377. Agreed again -- so how about adding that function <smile>?
  4378.  
  4379. > Regarding lists and dictionaries, the problem is this: if possible I
  4380. > would like to support value semantics for those, but the implementation
  4381. > makes this too difficult.
  4382.  
  4383. That's cool.  I think we agree there _are_ clear uses for lists & dicts,
  4384. as dict indices, provided object semantics are used.  I think we agree
  4385. too (me belatedly) that value semantics are more natural for Python.  But
  4386. I'm _not_ sure value semantics for lists & dicts, as dict indices, would
  4387. be useful enough to be worth the pain of implementing.
  4388.  
  4389. I do note that various LISPs implement dictionaries as "association
  4390. lists", and that the usual access function "assoc" uses the "equal"
  4391. predicate to see whether a key is present; and "equal" does usually
  4392. compare deep structure (with undefined behavior in the presence of
  4393. loops).  Any LISP'ers out there who think that's important to do?
  4394.  
  4395. can't-say-i've-seen-it-used!-ly y'rs  - tim
  4396.  
  4397. Tim Peters   tim@ksr.com
  4398. not speaking for Kendall Square Research Corp
  4399. 
  4400. 
  4401. Received: from relay.surfnet.nl by charon.cwi.nl with SMTP
  4402.     id AA06360 (5.65b/3.8/CWI-Amsterdam); Fri, 2 Apr 1993 15:39:27 +0200
  4403. X400-Received: by mta relay.surfnet.nl in /PRMD=surf/ADMD=400net/C=nl/; Relayed;
  4404.                Fri, 2 Apr 1993 15:38:20 +0200
  4405. X400-Received: by /PRMD=surf/ADMD=400net/C=nl/; Relayed;
  4406.                Fri, 2 Apr 1993 15:39:02 +0200
  4407. X400-Received: by /PRMD=uk.ac/ADMD= /C=gb/; Relayed;
  4408.                Fri, 2 Apr 1993 15:20:05 +0200
  4409. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  4410.                Fri, 2 Apr 1993 15:19:53 +0200
  4411. Date: Fri, 2 Apr 1993 15:19:53 +0200
  4412. X400-Originator: bevan@computer-science.manchester.ac.uk
  4413. X400-Recipients: python-list@cwi.nl
  4414. X400-Mts-Identifier: [/PRMD=UK.AC/ADMD= /C=GB/;<9304021319.AA14516@panda.cs.man]
  4415. X400-Content-Type: P2-1984 (2)
  4416. Content-Identifier: Re: Mutable o...
  4417. From: Stephen J Bevan <bevan@computer-science.manchester.ac.uk>
  4418. Message-Id: <9304021319.AA14516@panda.cs.man.ac.uk>
  4419. To: python-list@cwi.nl
  4420. References: <9303300500.AA15740@kaos.ksr.com>
  4421. Subject: Re: Mutable objects as mapping keys
  4422.  
  4423. >>>>> On Tue, 30 Mar 93 00:00:10 EST, Tim Peters <tim@ksr.com> wrote:
  4424. Tim> I do note that various LISPs implement dictionaries as "association
  4425. Tim> lists", and that the usual access function "assoc" uses the "equal"
  4426. Tim> predicate to see whether a key is present; and "equal" does usually
  4427. Tim> compare deep structure (with undefined behavior in the presence of
  4428. Tim> loops).
  4429.  
  4430. Scheme currently has "member" which does the above and "memq" which
  4431. uses pointer equality.
  4432.  
  4433. Tim> Any LISP'ers out there who think that's important to do?
  4434.  
  4435. This lisper prefers to let the user decide allow a user defined
  4436. comparision function to be used.
  4437.  
  4438. bevan
  4439. 
  4440. 
  4441. Replied: Tue, 13 Apr 1993 10:29:29 +0200
  4442. Replied: "Fraser@europarc.xerox.com python-list"
  4443. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  4444.     id AA18597 (5.65b/3.8/CWI-Amsterdam); Tue, 13 Apr 1993 10:20:18 +0200
  4445. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11599>; Tue, 13 Apr 1993 01:19:56 PDT
  4446. Received: by eros.EuroPARC.Xerox.COM with SMTP
  4447.     (5.65c/IDA-1.2.9) id AA14708; Tue, 13 Apr 1993 09:19:37 +0100
  4448. Message-Id: <199304130819.AA14708@eros.EuroPARC.Xerox.COM>
  4449. To: guido@cwi.nl
  4450. Subject: embedding python
  4451. Date:     Tue, 13 Apr 1993 01:19:36 PDT
  4452. From: Fraser@europarc.xerox.com
  4453.  
  4454.  
  4455. Guido, 
  4456.  
  4457. I'm addressing this to you, as the person most likely to have the answer,
  4458. but could you forward it to python-list if that's more appropriate.
  4459.  
  4460. There is good documentation for extending python, but only a brief mention
  4461. of embedding it in other applications. Have I missed anything?
  4462.  
  4463. Are there guidelines for doing this? Have many people done it? 
  4464. Is it just a case of calling routines in pythonrun.h?
  4465.  
  4466. Thanks,
  4467. Quentin
  4468.  
  4469. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4470. Quentin Stafford-Fraser         
  4471. Rank Xerox EuroPARC,            Some primal termite knocked on wood
  4472. Cambridge, UK            And tasted it, and found it good.
  4473. Tel: +44 223 341529          And that is why your cousin May
  4474. Fax: +44 223 341510          Fell through the parlour floor today.
  4475. Fraser@europarc.xerox.com    
  4476.  
  4477. 
  4478. 
  4479. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  4480.     id AA18878 (5.65b/3.8/CWI-Amsterdam); Tue, 13 Apr 1993 10:29:30 +0200
  4481. Received: by voorn.cwi.nl with SMTP
  4482.     id AA22953 (5.65b/3.8/CWI-Amsterdam); Tue, 13 Apr 1993 10:29:30 +0200
  4483. Message-Id: <9304130829.AA22953=guido@voorn.cwi.nl>
  4484. To: Fraser@europarc.xerox.com
  4485. Cc: python-list@cwi.nl
  4486. Subject: Re: embedding python 
  4487. In-Reply-To: Your message of "Tue, 13 Apr 1993 01:19:36 MDT."
  4488.              <199304130819.AA14708@eros.EuroPARC.Xerox.COM> 
  4489. From: Guido.van.Rossum@cwi.nl
  4490. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  4491. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  4492. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4493. Date: Tue, 13 Apr 1993 10:29:29 +0200
  4494. Sender: Guido.van.Rossum@cwi.nl
  4495.  
  4496. (This may be of general importance, hence the cc: to the list --Guido)
  4497.  
  4498. Quentin Fraser writes:
  4499.  
  4500. >There is good documentation for extending python, but only a brief mention
  4501. >of embedding it in other applications. Have I missed anything?
  4502.  
  4503. At the time I wrote that documentation it hadn't been done yet but the
  4504. code was designed to make it very simple.
  4505.  
  4506. >Are there guidelines for doing this?
  4507.  
  4508. Not yet.  As it's so simple, they follow below...
  4509.  
  4510. >Have many people done it?
  4511.  
  4512. At least one company has done it (for a GUI builder), one university
  4513. (for a VR system), and one person in my building (for an OO multimedia
  4514. system).  There may be more...
  4515.  
  4516. >Is it just a case of calling routines in pythonrun.h?
  4517.  
  4518. Basically, yes.  If you look at pythonmain.c, you'll see in what order
  4519. things have to be initialized:
  4520.  
  4521.     initargs(&argc, &argv);
  4522.     initall();
  4523.     setpythonargv(argc-optind, argv+optind);
  4524.         /* optind is the index of the script name in argv */
  4525.  
  4526. After this you are free to call any of the run* functions or
  4527. call_object() any time you like (or anything else that's available to
  4528. extensions).
  4529.  
  4530. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4531. 
  4532. 
  4533. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  4534.     id AA00945 (5.65b/3.8/CWI-Amsterdam); Wed, 14 Apr 1993 19:16:44 +0200
  4535. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  4536.     id AA27943; Wed, 14 Apr 93 10:17:20 -0700
  4537. Received: by eng2.sequent.com (5.65/1.34)
  4538.     id AA04184; Wed, 14 Apr 93 10:16:38 -0700
  4539. Message-Id: <9304141716.AA04184@eng2.sequent.com>
  4540. To: python-list@cwi.nl
  4541. Subject: Output disappears when using interrupt key
  4542. Priority: Normal
  4543. Precedence: first-class
  4544. Organization: Sequent Computer Systems, Inc.
  4545.           Service Technology - MailStop: WIL2-610
  4546.           15450 S.W. Koll Parkway
  4547.           Beaverton, OR  97006-6063
  4548. X-Phone: (503) 578-4404
  4549. X-Fax: (503) 578-4540
  4550. X-Uucp: ...!uunet!sequent!jaap
  4551. X-Internet: jaap@sequent.com
  4552. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  4553.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  4554.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  4555. Date: Wed, 14 Apr 93 10:16:37 PDT
  4556. From: Jaap Vermeulen <jaap@sequent.com>
  4557.  
  4558.  
  4559. Hi,
  4560.  
  4561. I'm seeing the following anomaly.  When executing the following
  4562. statements:
  4563.  
  4564. import sys
  4565. try: sys.stdin.readline()
  4566. except: print 'OK'
  4567.  
  4568. and generating a keyboard interrupt while readline() is waiting for
  4569. input, will *not* print the 'OK' on my system.
  4570.  
  4571. However, the following works:
  4572.  
  4573. import sys, time
  4574. try: sys.stdin.readline()
  4575. except: time.millisleep(300); print 'OK'
  4576.  
  4577. Here I will see OK after a keyboard interrupt while readline() is
  4578. waiting for input.
  4579.  
  4580. My question is: is this platform specific?  Do other people experience
  4581. the same problem?  Any other words of wisdom?
  4582.  
  4583. Thanks,
  4584.  
  4585.     -Jaap-
  4586. --
  4587. Jaap Vermeulen                    +--------------------------+
  4588.                         | Sequent Computer Systems |
  4589.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  4590.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  4591. 
  4592. 
  4593. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  4594.     id AA03394 (5.65b/3.8/CWI-Amsterdam); Wed, 14 Apr 1993 20:39:58 +0200
  4595. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa20575;
  4596.           14 Apr 93 14:39 EDT
  4597. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  4598.     id AA75886; Wed, 14 Apr 1993 14:39:39 -0400
  4599. Date: Wed, 14 Apr 1993 14:39:39 -0400
  4600. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  4601. Message-Id: <199304141839.AA75886@elvis.med.Virginia.EDU>
  4602. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  4603. To: Jaap Vermeulen <jaap@sequent.com>
  4604. Subject: Re: Output disappears when using interrupt key
  4605. Cc: python-list@cwi.nl
  4606.  
  4607. xOn Apr 14, 10:16, Jaap Vermeulen wrote:
  4608. > I'm seeing the following anomaly.  When executing the following
  4609. > statements:
  4610. > import sys
  4611. > try: sys.stdin.readline()
  4612. > except: print 'OK'
  4613. > and generating a keyboard interrupt while readline() is waiting for
  4614. > input, will *not* print the 'OK' on my system.
  4615. > [ ... alternate example deleted ] 
  4616. > My question is: is this platform specific?  Do other people experience
  4617. > the same problem?  Any other words of wisdom?
  4618.  
  4619.  
  4620. On my system ( IBM AIX 3.2 ; python sys.version '0.9.7 (DEC 20 1992)' )
  4621. the above does not seem to catch the keyboard interrupt until after 
  4622. a newline. But when it does get a newline, it does do the except
  4623. clause.
  4624.  
  4625. [ I also just tried SunOS 4.1 python sys.version 0.9.4 and got the same
  4626. results. ] 
  4627.  
  4628. >>> def try1(): 
  4629. ...   try: sys.stdin.readline() 
  4630. ...   except: print ' -OK.' 
  4631. ... 
  4632. >>> try1()
  4633.  
  4634. '\012'
  4635. >>> try1()
  4636. ^C^C^C^C^Cxxx
  4637.  
  4638.  -OK.
  4639.  
  4640. #            ^ <return-key> hit after several control-C and "x"'s 
  4641.  
  4642.  
  4643. "aaaa^Cbbbb\n"  does the same.
  4644. I would have expected that it should catch the first ^C right away,
  4645. but it seems to take an interrupt in a new-line terminated string
  4646. to cause the exception. 
  4647.  
  4648.  
  4649. I don't know where the problem is ( or what the expected behaviour
  4650. actually should be ) but I know stdio is prone to some odd behaviour 
  4651. when used in signal catchers, etc. Your post caught my eye because I
  4652. had been looking at some similar-but-different problems. I am
  4653. evaluating the 'sfio' package from netlib@research.att.com. 
  4654.  
  4655. [ Guido ( and others to whom it may concern):
  4656.   - you may want to take a look at sfio. It fixes some of the stdio 
  4657.   problems ( like interrupted i/o, allowing writes to read-opened
  4658.   files, etc. ). There is a different API that stdio-lib, with 
  4659.   some extra neat features, but there is a stdio emulation package 
  4660.   for backwards source compatability. I haven't used it enough yet
  4661.   to give a report. ] 
  4662.  
  4663.  
  4664. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  4665. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  4666. 
  4667. 
  4668. Replied: Thu, 15 Apr 1993 01:02:29 +0200
  4669. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> Jaap Vermeulen <jaap@sequent.com>, python-list@cwi.nl"
  4670. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  4671.     id AA03907 (5.65b/3.8/CWI-Amsterdam); Wed, 14 Apr 1993 20:59:37 +0200
  4672. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa23640;
  4673.           14 Apr 93 14:59 EDT
  4674. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  4675.     id AA73944; Wed, 14 Apr 1993 14:59:21 -0400
  4676. Date: Wed, 14 Apr 1993 14:59:21 -0400
  4677. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  4678. Message-Id: <199304141859.AA73944@elvis.med.Virginia.EDU>
  4679. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  4680. To: Jaap Vermeulen <jaap@sequent.com>
  4681. Subject: Re: Output disappears when using interrupt key
  4682. Cc: python-list@cwi.nl
  4683.  
  4684. Another curious "feature": 
  4685.  
  4686. # file try2.py
  4687. import sys
  4688. def try2():
  4689.   L = '######initial#string######'
  4690.   try: 
  4691.     L = sys.stdin.readline() 
  4692.     print '#try: '+L 
  4693.   except: 
  4694.     print '#except: '+L
  4695.     print '-OK.' 
  4696.   return L
  4697.  
  4698.  
  4699. >>> import try2
  4700. >>> try2.try2()
  4701. abc
  4702. #try: abc
  4703.  
  4704. 'abc\012'
  4705. >>> try2.try2()
  4706. ^C
  4707. #except: 
  4708.  
  4709. -OK.
  4710. '\012'
  4711. >>> try2.try2()
  4712. aaaaaaa^Cbbbbbbb
  4713. #except: bbbbbbb
  4714.  
  4715. -OK.
  4716. 'bbbbbbb\012'
  4717. >>> 
  4718.  
  4719.  
  4720. Of the top of my head, I would have expected "aaaaaaa" ( or nothing )
  4721. rather than "bbbbbbb" . 
  4722.  
  4723. But I expect that is is defined as "undefined" ?    :-)
  4724.  
  4725.  
  4726.  
  4727.  
  4728. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  4729. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  4730.  
  4731. 
  4732. 
  4733. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  4734.     id AA14435 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 01:02:32 +0200
  4735. Received: by voorn.cwi.nl with SMTP
  4736.     id AA27854 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 01:02:30 +0200
  4737. Message-Id: <9304142302.AA27854=guido@voorn.cwi.nl>
  4738. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  4739. Cc: Jaap Vermeulen <jaap@sequent.com>, python-list@cwi.nl
  4740. Subject: Re: Output disappears when using interrupt key 
  4741. In-Reply-To: Your message of "Wed, 14 Apr 1993 14:59:21 MDT."
  4742.              <199304141859.AA73944@elvis.med.Virginia.EDU> 
  4743. From: Guido.van.Rossum@cwi.nl
  4744. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  4745. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  4746. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4747. Date: Thu, 15 Apr 1993 01:02:30 +0200
  4748. Sender: Guido.van.Rossum@cwi.nl
  4749.  
  4750. I tried Steven's try() on two machines and the results differ.
  4751.  
  4752. On an SGI (System V, though with lots of BSD extensions) the ^C
  4753. triggers the except clause right away (as it should).
  4754.  
  4755. On a Sparc running SunOS 4.1 (BSD-based) I need a return after the ^C
  4756. and entering 'xxx^Cyyy\n' does indeed place 'yyy\n' in the string.
  4757. That is -- it does this most of the time.  Sometimes the initial
  4758. string remains in the variable L!
  4759.  
  4760. Knowing more about Python than most of you :-) I can try to explain
  4761. what's going on.  Interrupts in Python are handled by a signal handler
  4762. which sets a global flag and returns.  The interpreter looks at this
  4763. flag every ten pseudo-instructions or so.  Checking it more often is
  4764. expensive since the interface is a function call, to support the Mac
  4765. and DOS versions of the interrupt handling interface which works quite
  4766. differently.  This functional interface is also used by other parts
  4767. of Python that expect interrupts.
  4768.  
  4769. On System V-like systems, the signal handler causes the read() system
  4770. call that's buried deep inside stdio to return with an error (EINTR is
  4771. set), causing the stdio getc() call in Python (in "fileobject.c",
  4772. getline()) to return EOF, after which getline() checks for an
  4773. interrupt and reports an error -- the sys.stdin.readline() call never
  4774. returns successful.
  4775.  
  4776. However, on BSD-like systems, by default the read() call is
  4777. *restarted* after a signal handler returns normally (as is any other
  4778. system call that falls victim of a signal handler).  As a side effect
  4779. the system has emptied its input buffer (which hasn't been transferred
  4780. to stdio yet because it's waiting for a whole line to be entered).
  4781. The read() call then proceeds normally so if you entered 'xxx^Cyyy\n'
  4782. the 'xxx' is thrown away but the 'yyy\n' part is read normally.  But
  4783. the story isn't finished yet: since the interrupt handler *has* been
  4784. called, the global flag is waiting to be checked by the interpreter's
  4785. main loop.  Depending on where exactly it is it may first assign the
  4786. result of sys.stdin.readline() to L or first discover that an
  4787. interrupt has occurred -- which explains why I sometimes see L's
  4788. initial value.
  4789.  
  4790. I suspect that AIX 3.2's signal model is based more on BSD than on
  4791. System V (assuming Steven tried this on AIX -- he only said which
  4792. system he used for the first try).
  4793.  
  4794. I can't reproduce Jaap's problem (nor can Steven), so I suspect that
  4795. it is specific to his system.  When an interrupt occurs UNIX discards
  4796. any output that has been written by the application but not yet
  4797. transferred to the terminal.  Maybe Jaap's system is doing this
  4798. asynchronously and mistaking output written just after the interrupt
  4799. for output written just before (I don't know enough about tty drivers
  4800. to know if this is a reasonable assumption).
  4801.  
  4802. A solution?  Maybe I should just check for an interrupt after *every*
  4803. read, not just when getc() returns EOF.  This would be somewhat
  4804. expensive (an extra function call for *every* readline() and read()
  4805. call), but it could be made less expensive by doing it only for tty
  4806. devices (adding a field to the internal file structure containing the
  4807. outcome of isatty()).
  4808.  
  4809. Hoping this sheds enough light,
  4810.  
  4811. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4812. 
  4813. 
  4814. Replied: Thu, 15 Apr 1993 11:16:47 +0200
  4815. Replied: "python-list@cwi.nl "
  4816. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  4817. cc: Jaap Vermeulen <jaap@sequent.com>, python-list@cwi.nl
  4818. Subject: Re: Output disappears when using interrupt key 
  4819. In-reply-to: Your message of "Wed, 14 Apr 1993 14:59:21 MDT."
  4820.              <199304141859.AA73944@elvis.med.Virginia.EDU> 
  4821. From: Guido.van.Rossum@cwi.nl
  4822. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  4823. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  4824. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  4825. Date: Thu, 15 Apr 1993 01:02:30 +0200
  4826. Sender: guido
  4827.  
  4828. I tried Steven's try() on two machines and the results differ.
  4829.  
  4830. On an SGI (System V, though with lots of BSD extensions) the ^C
  4831. triggers the except clause right away (as it should).
  4832.  
  4833. On a Sparc running SunOS 4.1 (BSD-based) I need a return after the ^C
  4834. and entering 'xxx^Cyyy\n' does indeed place 'yyy\n' in the string.
  4835. That is -- it does this most of the time.  Sometimes the initial
  4836. string remains in the variable L!
  4837.  
  4838. Knowing more about Python than most of you :-) I can try to explain
  4839. what's going on.  Interrupts in Python are handled by a signal handler
  4840. which sets a global flag and returns.  The interpreter looks at this
  4841. flag every ten pseudo-instructions or so.  Checking it more often is
  4842. expensive since the interface is a function call, to support the Mac
  4843. and DOS versions of the interrupt handling interface which works quite
  4844. differently.  This functional interface is also used by other parts
  4845. of Python that expect interrupts.
  4846.  
  4847. On System V-like systems, the signal handler causes the read() system
  4848. call that's buried deep inside stdio to return with an error (EINTR is
  4849. set), causing the stdio getc() call in Python (in "fileobject.c",
  4850. getline()) to return EOF, after which getline() checks for an
  4851. interrupt and reports an error -- the sys.stdin.readline() call never
  4852. returns successful.
  4853.  
  4854. However, on BSD-like systems, by default the read() call is
  4855. *restarted* after a signal handler returns normally (as is any other
  4856. system call that falls victim of a signal handler).  As a side effect
  4857. the system has emptied its input buffer (which hasn't been transferred
  4858. to stdio yet because it's waiting for a whole line to be entered).
  4859. The read() call then proceeds normally so if you entered 'xxx^Cyyy\n'
  4860. the 'xxx' is thrown away but the 'yyy\n' part is read normally.  But
  4861. the story isn't finished yet: since the interrupt handler *has* been
  4862. called, the global flag is waiting to be checked by the interpreter's
  4863. main loop.  Depending on where exactly it is it may first assign the
  4864. result of sys.stdin.readline() to L or first discover that an
  4865. interrupt has occurred -- which explains why I sometimes see L's
  4866. initial value.
  4867.  
  4868. I suspect that AIX 3.2's signal model is based more on BSD than on
  4869. System V (assuming Steven tried this on AIX -- he only said which
  4870. system he used for the first try).
  4871.  
  4872. I can't reproduce Jaap's problem (nor can Steven), so I suspect that
  4873. it is specific to his system.  When an interrupt occurs UNIX discards
  4874. any output that has been written by the application but not yet
  4875. transferred to the terminal.  Maybe Jaap's system is doing this
  4876. asynchronously and mistaking output written just after the interrupt
  4877. for output written just before (I don't know enough about tty drivers
  4878. to know if this is a reasonable assumption).
  4879.  
  4880. A solution?  Maybe I should just check for an interrupt after *every*
  4881. read, not just when getc() returns EOF.  This would be somewhat
  4882. expensive (an extra function call for *every* readline() and read()
  4883. call), but it could be made less expensive by doing it only for tty
  4884. devices (adding a field to the internal file structure containing the
  4885. outcome of isatty()).
  4886.  
  4887. Hoping this sheds enough light,
  4888.  
  4889. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  4890. 
  4891. 
  4892. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  4893.     id AA21178 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 03:15:26 +0200
  4894. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  4895.     id AA07110; Wed, 14 Apr 93 18:16:01 -0700
  4896. Received: by eng2.sequent.com (5.65/1.34)
  4897.     id AA25668; Wed, 14 Apr 93 18:15:19 -0700
  4898. Message-Id: <9304150115.AA25668@eng2.sequent.com>
  4899. To: Guido.van.Rossum@cwi.nl
  4900. Cc: sdm7g@elvis.med.virginia.edu, python-list@cwi.nl
  4901. Subject: Re: Output disappears when using interrupt key
  4902. Priority: Normal
  4903. Precedence: first-class
  4904. Organization: Sequent Computer Systems, Inc.
  4905.           Service Technology - MailStop: WIL2-610
  4906.           15450 S.W. Koll Parkway
  4907.           Beaverton, OR  97006-6063
  4908. X-Phone: (503) 578-4404
  4909. X-Fax: (503) 578-4540
  4910. X-Uucp: ...!uunet!sequent!jaap
  4911. X-Internet: jaap@sequent.com
  4912. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  4913.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  4914.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  4915. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Thu, 15 Apr 1993 01:02:30 +0200.
  4916.              <9304142302.AA27854=guido@voorn.cwi.nl> 
  4917. Date: Wed, 14 Apr 1993 18:15:18 -0700
  4918. From: Jaap Vermeulen <jaap@sequent.com>
  4919.  
  4920.  
  4921. | I can't reproduce Jaap's problem (nor can Steven), so I suspect that
  4922. | it is specific to his system.  When an interrupt occurs UNIX discards
  4923. | any output that has been written by the application but not yet
  4924. | transferred to the terminal.  Maybe Jaap's system is doing this
  4925. | asynchronously and mistaking output written just after the interrupt
  4926. | for output written just before (I don't know enough about tty drivers
  4927. | to know if this is a reasonable assumption).
  4928.  
  4929. Well, suspicions confirmed!  It's a bug in the TCP/IP software w.r.t.
  4930. telnet sessions (that has been fixed in a later release).  I started
  4931. using rlogin and everything is hunky-dory.
  4932.  
  4933. Thanks for the help,
  4934.  
  4935.     -Jaap-
  4936. --
  4937. Jaap Vermeulen                    +--------------------------+
  4938.                         | Sequent Computer Systems |
  4939.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  4940.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  4941. 
  4942. 
  4943. Replied: Thu, 15 Apr 1993 10:08:46 +0200
  4944. Replied: "hzsbg01!jbuhrma@hvgtw.att.com "
  4945. Received: from att-out.att.com by charon.cwi.nl with SMTP
  4946.     id AA00307 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 09:30:21 +0200
  4947. From: hzsbg01!jbuhrma@hvgtw.att.com
  4948. Received: from hzsbc03 by hzsbg01 (4.1/SMI-4.1)
  4949.     id AA01152; Thu, 15 Apr 93 09:24:54 +0200
  4950. Date: Thu, 15 Apr 93 09:24:54 +0200
  4951. Original-From: hzsbg01!jbuhrma
  4952. Message-Id: <9304150724.AA01152@hzsbg01>
  4953. To: Guido.van.Rossum@cwi.nl
  4954. Subject: Re: Output disappears when using interrupt key
  4955.  
  4956. > On an SGI (System V, though with lots of BSD extensions) the ^C
  4957. > triggers the except clause right away (as it should).
  4958.                                          ^^^^^^^^^^^^
  4959. > [...] On System V-like systems, the signal handler causes the read()
  4960. > system call that's buried deep inside stdio to return with an error
  4961. > (EINTR is set), causing the stdio getc() call in Python (in
  4962. > "fileobject.c", getline()) to return EOF, after which getline() checks
  4963. > for an interrupt and reports an error -- the sys.stdin.readline() call
  4964. > never returns successful.
  4965.  
  4966. > However, on BSD-like systems, by default the read() call is
  4967. > *restarted* after a signal handler returns normally
  4968.  
  4969. > [...] A solution?  Maybe I should just check for an interrupt after
  4970. > *every* read, not just when getc() returns EOF.  This would be
  4971. > somewhat expensive (an extra function call for *every* readline() and
  4972. > read() call), but it could be made less expensive by doing it only for
  4973. > tty devices (adding a field to the internal file structure containing
  4974. > the outcome of isatty()).
  4975.  
  4976. Another possibility: Let BSD-like system calls react on interrupts the
  4977. same way as is done on System V based systems.  You probably already
  4978. know this, but the read(2) man page for SunOS 4.1.3 suggests that this
  4979. is possible:
  4980.  
  4981.       If the process calling read()    or readv() receives a signal
  4982.       before any data are read, the    system call is restarted
  4983.       unless the process explicitly    set the    signal to interrupt
  4984.       the call using sigvec() or sigaction() (see the discussions
  4985.       of SV_INTERRUPT on sigvec(2) and SA_INTERRUPT    on
  4986.       sigaction(3V)).  If read() or    readv()    is interrupted by a
  4987.       signal after successfully reading some data, it returns the
  4988.       number of bytes read.
  4989.  
  4990. Regards,
  4991.  
  4992. -- Jan-Hein Buhrman -- AT&T Huizen NL -- <jbuhrma%hzsbg01@hvlpa.att.com> --
  4993. ---------------------- +31 35 87.4278 --- ...!att!hvlpa!hzsbg01!jbuhrma ---
  4994. ``Relax..., you're quite safe here'' --- Lady on Art of Noise's Paranoimia
  4995.  
  4996. 
  4997. 
  4998. To: hzsbg01!jbuhrma@hvgtw.att.com
  4999. Subject: Re: Output disappears when using interrupt key 
  5000. In-reply-to: Your message of "Thu, 15 Apr 1993 09:24:54 MDT."
  5001.              <9304150724.AA01152@hzsbg01> 
  5002. From: Guido.van.Rossum@cwi.nl
  5003. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  5004. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  5005. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  5006. Date: Thu, 15 Apr 1993 10:08:46 +0200
  5007. Sender: guido
  5008.  
  5009. >Another possibility: Let BSD-like system calls react on interrupts the
  5010. >same way as is done on System V based systems.  You probably already
  5011. >know this, but the read(2) man page for SunOS 4.1.3 suggests that this
  5012. >is possible:
  5013. [...]
  5014.  
  5015. Zijn er niet verschillende BSD varianten in de handel die dit anders
  5016. doen?  Ik dacht dat in elk geval "oud" BSD (ik weet niet hoe oud --
  5017. 4.1 of 4.2) een andere interface had...  Maar ik zal er eens naar
  5018. kijken...
  5019.  
  5020. (Had je bewust alleen naar mij gereplied?)
  5021.  
  5022. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5023. 
  5024. 
  5025. Replied: Thu, 15 Apr 1993 11:11:15 +0200
  5026. Replied: "hzsbg01!jbuhrma@hvgtw.att.com "
  5027. Received: from att-out.att.com by charon.cwi.nl with SMTP
  5028.     id AA02865 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 10:35:20 +0200
  5029. From: hzsbg01!jbuhrma@hvgtw.att.com
  5030. Received: from hzsbc03 by hzsbg01 (4.1/SMI-4.1)
  5031.     id AA08314; Thu, 15 Apr 93 10:30:12 +0200
  5032. Date: Thu, 15 Apr 93 10:30:12 +0200
  5033. Original-From: hzsbg01!jbuhrma
  5034. Message-Id: <9304150830.AA08314@hzsbg01>
  5035. To: Guido.van.Rossum@cwi.nl
  5036. Subject: Re: Output disappears when using interrupt key
  5037.  
  5038. > >Another possibility: Let BSD-like system calls react on interrupts the
  5039. > >same way as is done on System V based systems.  You probably already
  5040. > >know this, but the read(2) man page for SunOS 4.1.3 suggests that this
  5041. > >is possible:
  5042. > [...]
  5043. > Zijn er niet verschillende BSD varianten in de handel die dit anders
  5044. > doen?  Ik dacht dat in elk geval "oud" BSD (ik weet niet hoe oud --
  5045. > 4.1 of 4.2) een andere interface had...  Maar ik zal er eens naar
  5046. > kijken...
  5047.  
  5048. Vast wel.  Dit is waarschijnlijk iets van de laatste BSD release(s).
  5049.  
  5050. Vroeger had je misschien nog wel een andere truuk, waarbij the read
  5051. versie die interruptable was een andere naam had en via een #define naar
  5052. `read' werd gemapt (maar misschien ben ik nu wel in de war met
  5053. non-blocking read versies die op die manier gemapt werden voor getruukte
  5054. multiple-thread libs, zonder LWP support in de kernel).  Kortom: ik weet
  5055. het niet!
  5056.  
  5057. > (Had je bewust alleen naar mij gereplied?)
  5058.  
  5059. Ja, bescheiden van aard :-).  Ik weet dat je het forward-t als je het
  5060. van algemeen belang acht.
  5061.  
  5062. -- Jan-Hein Buhrman -- AT&T Huizen NL -- <jbuhrma%hzsbg01@hvlpa.att.com> --
  5063. ---------------------- +31 35 87.4278 --- ...!att!hvlpa!hzsbg01!jbuhrma ---
  5064. There is a severe danger that we might finish the program today
  5065. 
  5066. 
  5067. To: hzsbg01!jbuhrma@hvgtw.att.com
  5068. Subject: Re: Output disappears when using interrupt key 
  5069. In-reply-to: Your message of "Thu, 15 Apr 1993 10:30:12 MDT."
  5070.              <9304150830.AA08314@hzsbg01> 
  5071. From: Guido.van.Rossum@cwi.nl
  5072. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  5073. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  5074. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  5075. Date: Thu, 15 Apr 1993 11:11:15 +0200
  5076. Sender: guido
  5077.  
  5078. Sjoerd deed me een andere truc aan de hand:
  5079.  
  5080. #ifdef SV_INTERRUPT
  5081.     siginterrupt(SIGINT, 1);
  5082. #endif
  5083.  
  5084. I'll summarize to the list, as they say...
  5085.  
  5086. Doei!
  5087.  
  5088. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5089. 
  5090. 
  5091. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  5092.     id AA04572 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 11:16:52 +0200
  5093. Received: by voorn.cwi.nl with SMTP
  5094.     id AA29078 (5.65b/3.8/CWI-Amsterdam); Thu, 15 Apr 1993 11:16:47 +0200
  5095. Message-Id: <9304150916.AA29078=guido@voorn.cwi.nl>
  5096. To: python-list@cwi.nl
  5097. Subject: Re: Output disappears when using interrupt key 
  5098. In-Reply-To: Your message of "Thu, 15 Apr 1993 01:02:30 MDT."
  5099. From: Guido.van.Rossum@cwi.nl
  5100. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  5101. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  5102. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  5103. Date: Thu, 15 Apr 1993 11:16:47 +0200
  5104. Sender: Guido.van.Rossum@cwi.nl
  5105.  
  5106. In response to Steven's problem of ^C requiring a newline, some people
  5107. suggested that BSD has a way to turn off system call restarting.  The
  5108. following fix works on our version of SunOS (4.1.1); please try it if
  5109. you have this problem and see if it compiles and works.  (The symbol
  5110. SV_INTERRUPT is defined in <sys/signal.h> or <signal.h>.)
  5111.  
  5112. -------------------------------------------------------------------------------
  5113. diff -c -r2.8 intrcheck.c
  5114. *** 2.8 1993/03/29 10:41:47
  5115. --- intrcheck.c 1993/04/15 08:58:58
  5116. ***************
  5117. *** 140,145 ****
  5118. --- 140,154 ----
  5119.   {
  5120.         if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  5121.                 signal(SIGINT, intcatcher);
  5122. + #ifdef SV_INTERRUPT
  5123. +       /* This is for SunOS and other modern BSD derivatives.
  5124. +          It means that system calls (like read()) are not restarted
  5125. +          after an interrupt.  This is necessary so interrupting a
  5126. +          read() or readline() call works as expected.
  5127. +          XXX On old BSD (pure 4.2 or older) you may have to do this
  5128. +          differently! */
  5129. +       siginterrupt(SIGINT, 1);
  5130. + #endif
  5131.   }
  5132.   
  5133.   int
  5134. -------------------------------------------------------------------------------
  5135.  
  5136. Thankyou Jan-Hein Buhrman and Sjoerd Mullender,
  5137.  
  5138. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5139. 
  5140. 
  5141. Received: from guppie.cwi.nl by charon.cwi.nl with SMTP
  5142.     id AA18052 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 19:49:25 +0200
  5143. Received: by guppie.cwi.nl with SMTP
  5144.     id AA04778 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 17:49:24 GMT
  5145. Message-Id: <9305101749.AA04778=guido@guppie.cwi.nl>
  5146. To: Jaap Vermeulen <jaap@sequent.com>
  5147. Cc: python-list@cwi.nl
  5148. Subject: Re: SystemExit 
  5149. In-Reply-To: Your message of "Mon, 10 May 1993 10:38:45 MDT."
  5150.              <9305101738.AA23653@eng2.sequent.com> 
  5151. From: Guido.van.Rossum@cwi.nl
  5152. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  5153. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  5154. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  5155. Date: Mon, 10 May 1993 17:49:24 +0200
  5156. Sender: Guido.van.Rossum@cwi.nl
  5157.  
  5158. On the contrary, SystemExit is a big improvement.  Now you can do
  5159. things like
  5160.  
  5161.     "put the tty in raw mode"
  5162.     try:
  5163.         "some code that may call sys.exit(n) somewhere deep inside"
  5164.     finally:
  5165.         "put the tty in cooked mode again"
  5166.  
  5167. without having to worry about the possibility that you never hit the
  5168. finally clause.  It is still possible but less likely during normal
  5169. code.  Nobody in their right mind would use posix._exit(n) except to
  5170. exit from a forked child, but lots of code may call sys.exit(n) -- as
  5171. you have experienced, otherwise you wouldn't have started this thread
  5172. in the first place :-)
  5173.  
  5174. Code that uses an unqualified except clause is always suspect.  It may
  5175. mask exceptions caused deep inside that you didn't know were possible,
  5176. such as SystemError, MemoryError or TypeError in code that you thought
  5177. had no bugs.
  5178.  
  5179. A solution to your problem that is more elegant than testing the value
  5180. of sys.exc_type (which is really meant for the debugger only), and
  5181. which generalizes slightly better as well, is the following:
  5182.  
  5183.     try:
  5184.         "some code that may raise any exception"
  5185.     except SystemExit, status:
  5186.         raise SystemExit, status
  5187.     except:
  5188.         "handle any other kind of error"
  5189.  
  5190. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5191.  
  5192. PS: I'll reply to your previous mail later since the issues are more
  5193. complicated...
  5194. 
  5195. 
  5196. Replied: Mon, 10 May 1993 18:11:22 +0200
  5197. Replied: "Lance Ellinghouse <lance@markv.com> "
  5198. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  5199.     id AA14984 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 18:02:02 +0200
  5200. Received: by hermix.markv.com id aa02307; 10 May 93 8:59 PDT
  5201. From: Lance Ellinghouse <lance@markv.com>
  5202. X-Mailer: SCO System V Mail (version 3.2)
  5203. To: hegt@lebe.iaci.kun.nl
  5204. Subject: Re: python/stdwin/motif
  5205. Cc: python-list@cwi.nl
  5206. Date: Mon, 10 May 93 8:50:25 PDT
  5207. Message-Id:  <9305100850.aa01768@hermix.markv.com>
  5208.  
  5209. > Guido told me, that he is thinking about going to support Motif as the
  5210. > underlying window system of Python rather than his own STDWIN.
  5211.  
  5212. This is very good news!
  5213.  
  5214. > I can think of some reasons why this is a good idea, but also why I
  5215. > would personally not make this choice:
  5216. > - as far as I can see there is not much support for Motif other than as
  5217. >   a widget set on top of X11
  5218.  
  5219. Incorrect. Almost every PC X-windows package supports Motif, almost every
  5220. UNIX platforms supports Motif, Even Mac-X supports Motif.. Remember,
  5221. once the application is compiled and linked with Motif libraries, 
  5222. the Widget set is INDEPENDENT of the supplied X-windows system since
  5223. everything folds down to Xlib. The server does not have to have
  5224. Motif on it at all.. 
  5225.  
  5226. > - although X11 is available on several platforms, not all of them
  5227. >   include Motif, that is for a reasonable price; practically speaking,
  5228. >   I think that this means the end of window-based development using
  5229. >   Python on non-unix systems
  5230.  
  5231. Motif is going into the public domain. It will no longer be owned by OSF
  5232. in the very near future. it will be similar to X then. You will
  5233. be able to FTP and grab the Motif sources (Don't ask me the source
  5234. of my info).
  5235.  
  5236. > - what is the purpose a of window-system binding for Python and wouldn't
  5237. >   we rather have some portable Xlib level kind of window functionality
  5238. >   on all the obvious platforms (mac/pc/unix-x11); we could think of the
  5239. >   XVT type of solution, which is more or less an extension of the
  5240. >   thoughts behind STDWIN, but developed from the other end, i.e. from
  5241. >   existing window systems
  5242.  
  5243. Motif is more standard then STDWIN. People like the look and feel of
  5244. Motif. The first time I ran a STDWIN program, I thought it looked 
  5245. like a toy. Put a nice Motif look to it and it can become a product.
  5246.  
  5247. > I think that the underlying question is: who is using Python and for
  5248. > what? As a newcomer to Python and this list I have no idea about that.
  5249. > My own main interest is cross-platform non-standard (so: not MS-Win,
  5250. > Motif, OpenLook etc.) GUI prototyping.
  5251.          ^^^^^^^^ OpenLook is dead. Sun is dropping it completely.
  5252.  
  5253. I know that I will very much enjoy the Motif interface for Python!
  5254. I am creating a commercial product based on Python and the STDWIN 
  5255. interface does not look professional enough. There is no 
  5256. need to discontinue to use STDWIN for those that need it, but I 
  5257. for one need Motif.
  5258.  
  5259. Lance Ellinghouse
  5260. lance@markv.com
  5261. 
  5262. 
  5263. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  5264.     id AA15387 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 18:12:30 +0200
  5265. Received: by voorn.cwi.nl with SMTP
  5266.     id AA28879 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 18:12:29 +0200
  5267. Message-Id: <9305101612.AA28879=guido@voorn.cwi.nl>
  5268. To: python-list@cwi.nl
  5269. Subject: Re: python/stdwin/motif
  5270. Date: Mon, 10 May 1993 18:12:28 +0200
  5271. From: Guido van Rossum <Guido.van.Rossum@cwi.nl>
  5272.  
  5273. [">" is Lance Ellinghouse, "> >" is Rob Hegt:]
  5274.  
  5275. > > I can think of some reasons why this is a good idea, but also why I
  5276. > > would personally not make this choice:
  5277. > > 
  5278. > > - as far as I can see there is not much support for Motif other than as
  5279. > >   a widget set on top of X11
  5280. > Incorrect. Almost every PC X-windows package supports Motif, almost every
  5281. > UNIX platforms supports Motif, Even Mac-X supports Motif.. Remember,
  5282. > once the application is compiled and linked with Motif libraries, 
  5283. > the Widget set is INDEPENDENT of the supplied X-windows system since
  5284. > everything folds down to Xlib. The server does not have to have
  5285. > Motif on it at all.. 
  5286.  
  5287. Hmm, are you implying that there are PC X-windows packages that allow
  5288. *clients* to run under DOS or Windows?  All I know if in this area are
  5289. packages that are usable as an X server, allowing you to run X clients
  5290. remotely on a UNIX machine with their windows on your PC.  But what
  5291. Rob is worried about is that he won't be able to write portable
  5292. *clients* -- if they use Motif they will have to run an a UNIX box.
  5293. Or have I missed something?  (Quite possible, I don't follow all the
  5294. X-related market news any more...)
  5295.  
  5296. > Motif is more standard then STDWIN. People like the look and feel of
  5297. > Motif. The first time I ran a STDWIN program, I thought it looked 
  5298. > like a toy. Put a nice Motif look to it and it can become a product.
  5299.  
  5300. One thing I'm thinking of is to create a STDWIN port that uses Motif
  5301. instead of bare Xlib underneath.  It may even be possible to do this
  5302. entirely in Python, once my Motif/Xt port has sufficient Xlib
  5303. functionality (currently it has none).  This would help Rob as well:
  5304. he can continue to use STDWIN for "toy" apps on his Mac or PC, but on
  5305. UNIX boxes his apps will follow the Motif style.
  5306.  
  5307. (To make one thing clear: I don't really plan to discontinue STDWIN,
  5308. but I don't want to make additions to it either, sice the audience is
  5309. really too small.  Had there been a Windows port two years ago, the
  5310. situation might have been different...  Sigh.)
  5311.  
  5312. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5313. 
  5314. 
  5315. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  5316.     id AA16179 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 18:39:09 +0200
  5317. From: Lance Ellinghouse <lance@markv.com>
  5318. X-Mailer: SCO System V Mail (version 3.2)
  5319. To: Guido.van.Rossum@cwi.nl
  5320. Subject: Re: python/stdwin/motif
  5321. Cc: python-list@cwi.nl
  5322. Date: Mon, 10 May 93 9:35:45 PDT
  5323. Message-Id:  <9305100935.aa05771@hermix.markv.com>
  5324.  
  5325. ["> " is Guido, "> >" is Lance Ellinghouse, "> > >" is Rob Hegt:]
  5326. > > > I can think of some reasons why this is a good idea, but also why I
  5327. > > > would personally not make this choice:
  5328. > > > 
  5329. > > > - as far as I can see there is not much support for Motif other than as
  5330. > > >   a widget set on top of X11
  5331. > > 
  5332. > > Incorrect. Almost every PC X-windows package supports Motif, almost every
  5333. > > UNIX platforms supports Motif, Even Mac-X supports Motif.. Remember,
  5334. > > once the application is compiled and linked with Motif libraries, 
  5335. > > the Widget set is INDEPENDENT of the supplied X-windows system since
  5336. > > everything folds down to Xlib. The server does not have to have
  5337. > > Motif on it at all.. 
  5338. > Hmm, are you implying that there are PC X-windows packages that allow
  5339. > *clients* to run under DOS or Windows?  All I know if in this area are
  5340. > packages that are usable as an X server, allowing you to run X clients
  5341. > remotely on a UNIX machine with their windows on your PC.  But what
  5342. > Rob is worried about is that he won't be able to write portable
  5343. > *clients* -- if they use Motif they will have to run an a UNIX box.
  5344. > Or have I missed something?  (Quite possible, I don't follow all the
  5345. > X-related market news any more...)
  5346.  
  5347. DeskView/X allows you to compile X *CLIENTS* under
  5348. DOS that talk X. They have Motif libraries also. There are 
  5349. also a couple others that i have heard about but their names don't
  5350. jump out at me (since I don't deal with DOS at all..).
  5351.  
  5352. > > Motif is more standard then STDWIN. People like the look and feel of
  5353. > > Motif. The first time I ran a STDWIN program, I thought it looked 
  5354. > > like a toy. Put a nice Motif look to it and it can become a product.
  5355. > One thing I'm thinking of is to create a STDWIN port that uses Motif
  5356. > instead of bare Xlib underneath.  It may even be possible to do this
  5357. > entirely in Python, once my Motif/Xt port has sufficient Xlib
  5358. > functionality (currently it has none).  This would help Rob as well:
  5359. > he can continue to use STDWIN for "toy" apps on his Mac or PC, but on
  5360. > UNIX boxes his apps will follow the Motif style.
  5361. > (To make one thing clear: I don't really plan to discontinue STDWIN,
  5362. > but I don't want to make additions to it either, sice the audience is
  5363. > really too small.  Had there been a Windows port two years ago, the
  5364. > situation might have been different...  Sigh.)
  5365.  
  5366. This is the way that I see things.. STDWIN is still there and people
  5367. can make inprovements as people need... MotifWIN comes into being
  5368. and people make improvements as people need. Both have their uses.
  5369. People programming in Python can choose which to program against
  5370. by "import"'ing the one they want. There is no need for one to REPLACE
  5371. the other.
  5372.  
  5373. Lance Ellinghouse
  5374. lance@markv.com
  5375.  
  5376. 
  5377. 
  5378. Received: from srv01s4.cas.org by charon.cwi.nl with SMTP
  5379.     id AA16791 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 19:02:07 +0200
  5380. Date: Mon, 10 May 93 13:01:59 EDT
  5381. From: jcv26@cas.org (Jon Vander Hill)
  5382. Message-Id: <9305101701.AA02842@cas.org>
  5383. To: Lance Ellinghouse <lance@markv.com>
  5384. Cc: python-list@cwi.nl
  5385. Subject: Re: python/stdwin/motif
  5386. In-Reply-To: <9305100850.aa01768@hermix.markv.com>
  5387. References: <9305100850.aa01768@hermix.markv.com>
  5388.  
  5389. >>>>> On Mon, 10 May 93 8:50:25 PDT, Lance Ellinghouse <lance@markv.com> said:
  5390.  
  5391. > Incorrect. Almost every PC X-windows package supports Motif, almost every
  5392. > UNIX platforms supports Motif, Even Mac-X supports Motif.. Remember,
  5393. > once the application is compiled and linked with Motif libraries, 
  5394. > the Widget set is INDEPENDENT of the supplied X-windows system since
  5395. > everything folds down to Xlib. The server does not have to have
  5396. > Motif on it at all.. 
  5397.  
  5398. Anyone running Motif applications on under Sun's OpenWindows can
  5399. attest to that!  SunOS is the only UNIX I know of that doesn't ship
  5400. with a Motif library (although I heard they were handing one out
  5401. at a recent developers conference).  Sun is supposed to have a Motif
  5402. library in Solaris 2.2.
  5403.  
  5404. > Motif is going into the public domain. It will no longer be owned by OSF
  5405. > in the very near future. it will be similar to X then. You will
  5406. > be able to FTP and grab the Motif sources (Don't ask me the source
  5407. > of my info).
  5408.  
  5409. Okay I won't ask (but I'm intensely curious).  Can you provide a time
  5410. frame?  Personally, I think this must happen for UNIX vendors to
  5411. survive the NT juggernaut.
  5412.  
  5413. >> I think that the underlying question is: who is using Python and
  5414. for >> what? As a newcomer to Python and this list I have no idea
  5415. about that.  >> My own main interest is cross-platform non-standard
  5416. (so: not MS-Win, >> Motif, OpenLook etc.) GUI prototyping.  > ^^^^^^^^
  5417. OpenLook is dead. Sun is dropping it completely.
  5418.  
  5419. As I understand it, Sun is moving toward an interoperability standard
  5420. (along with basically any UNIX vendor who doesn't want to get blown
  5421. away by NT) of which Motif is a part.  How much of this is mere
  5422. corporate posturing is anyone's guess given that Windows NT is
  5423. still not a product.  I give OpenLook about two more years as support
  5424. gradually diminishes.
  5425.  
  5426. Overall, I think Motif and Python would be good for eachother.
  5427.  
  5428. Jon Vander Hill
  5429. jon@cas.org
  5430.  
  5431.  
  5432.  
  5433.  
  5434.  
  5435. 
  5436. 
  5437. Replied: Mon, 10 May 1993 21:17:07 +0200
  5438. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list"
  5439. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  5440.     id AA17345 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 19:24:09 +0200
  5441. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  5442.     id AA02251; Mon, 10 May 93 10:24:10 -0700
  5443. Received: by eng2.sequent.com (5.65/1.34)
  5444.     id AA21460; Mon, 10 May 93 10:24:00 -0700
  5445. Message-Id: <9305101724.AA21460@eng2.sequent.com>
  5446. To: python-list@cwi.nl
  5447. Subject: Some suggestion for python classes
  5448. Priority: Normal
  5449. Precedence: first-class
  5450. Organization: Sequent Computer Systems, Inc.
  5451.           Service Technology - MailStop: WIL2-610
  5452.           15450 S.W. Koll Parkway
  5453.           Beaverton, OR  97006-6063
  5454. X-Phone: (503) 578-4404
  5455. X-Fax: (503) 578-4540
  5456. X-Uucp: ...!uunet!sequent!jaap
  5457. X-Internet: jaap@sequent.com
  5458. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  5459.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  5460.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  5461. Date: Mon, 10 May 93 10:23:59 PDT
  5462. From: Jaap Vermeulen <jaap@sequent.com>
  5463.  
  5464.  
  5465. Having used the python classes for a bit, I came up with some pieces
  5466. that would make life a lot easier when using the classes within
  5467. python.  They boil down to 3 suggestions.  I used some simple
  5468. examples.
  5469.  
  5470. 1)  When using a class method, it would be nice if the calling class
  5471.     would be added as the 1st argument of the method.
  5472.  
  5473.     First let me explain the nomenclature.  A class method is a method
  5474.     invoked through the class instead of the method.  I.e.
  5475.  
  5476.     class foo:
  5477.     def bar():
  5478.         something
  5479.  
  5480.     Invoking foo.bar() is invoking a class method.  You could invoke
  5481.     the same method as a instance method, foo().bar(), however, it
  5482.     would result in a 'TypeError: arg cound mismatch' since the
  5483.     instance itself is automatically prepended to the argument list.
  5484.     What I propose is to do the same when you invoke the method as a
  5485.     class method, and prepend the class to the method.  This would
  5486.     result in:
  5487.  
  5488.     class foo:
  5489.     def bar(self):
  5490.         print type(self)
  5491.  
  5492.     Invoking foo.bar() would result in <type 'class'>, invoking
  5493.     foo().bar() would result in <type 'instance'>. It is up to the
  5494.     programmer to correctly code, invoke and identify class method vs.
  5495.     instance methods (as with a lot of other things in python).
  5496.  
  5497.     The benefit would be that you can define a class method in a base
  5498.     class, and still have access to the invoking class. i.e.
  5499.  
  5500.     class foo:
  5501.     def new(self):
  5502.         new_instance = self()
  5503.         ...
  5504.         return new_instance
  5505.  
  5506.     class bar(foo):
  5507.     ...
  5508.  
  5509.     Invoking bar.new() would return an instance of bar.  The current
  5510.     work-around is to invoke the class method as bar.new(bar).
  5511.  
  5512. 2)  It would be nice to have a special operator to implement the
  5513.     'super' functionality.  This functionality allows you to start
  5514.     searching for a method starting at the base classes, not the
  5515.     current class.  The current workaround is to define a function to
  5516.     delete the method from the current class (if it's there), retrieve
  5517.     it using the normal method, and replacing the method in the current
  5518.     class.  This allows you to write:
  5519.  
  5520.     class bar(foo):
  5521.     def new(self):
  5522.         new_instance = super(self, 'new')(self)
  5523.         ...
  5524.         return new_instance
  5525.  
  5526.     What I would like to see is some special operator that does this
  5527.     for you, e.g. using a carrot:
  5528.  
  5529.         new_instance = self^new()
  5530.  
  5531. 3)  It would be nice to be able to retrieve the name of a class.  The
  5532.     attribute exists, but is empty.  I.e. bar.__name__ returns None.
  5533.     Also, the address operator Guido was talking about would come in
  5534.     very handy, since you would be able to define something like this
  5535.     (given that '&' is the address operator):
  5536.  
  5537.     class bar(foo):
  5538.     def __repr__(self):
  5539.         try: return '<class ' + self.__name__ + 'at ' + `&self`
  5540.         except:
  5541.         return '<instance ' + self.__class__.__name__ + 'at ' + `&self`
  5542.  
  5543.     This brings up another point, and that is that __repr__ currently
  5544.     doesn't work for classes, it would be nice if it did.
  5545.  
  5546. Suggestions and comments are welcome.
  5547.  
  5548.  
  5549.     -Jaap-
  5550. --
  5551. Jaap Vermeulen                    +--------------------------+
  5552.                         | Sequent Computer Systems |
  5553.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  5554.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  5555. 
  5556. 
  5557. Replied: Mon, 10 May 1993 17:49:23 +0200
  5558. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list"
  5559. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  5560.     id AA17663 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 19:38:52 +0200
  5561. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  5562.     id AA02737; Mon, 10 May 93 10:38:55 -0700
  5563. Received: by eng2.sequent.com (5.65/1.34)
  5564.     id AA23653; Mon, 10 May 93 10:38:46 -0700
  5565. Message-Id: <9305101738.AA23653@eng2.sequent.com>
  5566. To: python-list@cwi.nl
  5567. Subject: SystemExit
  5568. Priority: Normal
  5569. Precedence: first-class
  5570. Organization: Sequent Computer Systems, Inc.
  5571.           Service Technology - MailStop: WIL2-610
  5572.           15450 S.W. Koll Parkway
  5573.           Beaverton, OR  97006-6063
  5574. X-Phone: (503) 578-4404
  5575. X-Fax: (503) 578-4540
  5576. X-Uucp: ...!uunet!sequent!jaap
  5577. X-Internet: jaap@sequent.com
  5578. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  5579.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  5580.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  5581. Date: Mon, 10 May 1993 10:38:45 -0700
  5582. From: Jaap Vermeulen <jaap@sequent.com>
  5583.  
  5584.  
  5585. I have some gripes about the SystemExit.
  5586.  
  5587.  
  5588. Firstly all the code that used to work, such as:
  5589.  
  5590. try:
  5591.     some code that includes an sys.exit() deep down
  5592. except:
  5593.     something else
  5594.  
  5595. doesn't work any more since it's entering the except.  What I want is
  5596. catching all possible scenarios *except* system exit.  Yes I could use
  5597. posix._exit(), but that doesn't flush things properly etc. 
  5598.  
  5599. Now I'm forced to write:
  5600.  
  5601. try:
  5602.     some code that includes and sys.exit() deep down
  5603. except:
  5604.     if sys.exc_type == SystemExit: sys.exit()
  5605.     something else
  5606.  
  5607. for every such contruct.
  5608.  
  5609. Furthermore, if I were to use the posix._exit() function, I can't on DOS
  5610. since it doesn't exist. As a matter of fact I had to clean up the os.py
  5611. module to work properly by changing the line:
  5612.  
  5613. try:
  5614.     from posix import *
  5615.     from posix import _exit
  5616.     name = 'posix'
  5617.     ...
  5618.  
  5619. to:
  5620.  
  5621. try:
  5622.     from posix import *
  5623.     try: from posix import _exit
  5624.     except: pass
  5625.     name = 'posix'
  5626.     ...
  5627.  
  5628. I know that I'm the one that was asking for a cleanup function, which
  5629. Guido dutifully implemented, but I didn't ask for an exception if I
  5630. just want to exit.  Except for the solutions outlined above, does
  5631. somebody else come up with a convenient solution?
  5632.  
  5633. Looks like backwards compatibility is slightly broken here.  And I
  5634. don't really see the rational for this change, since I could have
  5635. raised the exception myself if I needed it.
  5636.  
  5637. Thanks,
  5638.  
  5639.     -Jaap-
  5640. --
  5641. Jaap Vermeulen                    +--------------------------+
  5642.                         | Sequent Computer Systems |
  5643.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  5644.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  5645. 
  5646. 
  5647. Replied: Mon, 10 May 1993 20:48:42 +0200
  5648. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list@cwi.nl"
  5649. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  5650.     id AA18821 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 20:11:25 +0200
  5651. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  5652.     id AA04472; Mon, 10 May 93 11:11:26 -0700
  5653. Received: by eng2.sequent.com (5.65/1.34)
  5654.     id AA29028; Mon, 10 May 93 11:11:15 -0700
  5655. Message-Id: <9305101811.AA29028@eng2.sequent.com>
  5656. To: Guido.van.Rossum@cwi.nl
  5657. Cc: python-list@cwi.nl
  5658. Subject: Re: SystemExit
  5659. Priority: Normal
  5660. Precedence: first-class
  5661. Organization: Sequent Computer Systems, Inc.
  5662.           Service Technology - MailStop: WIL2-610
  5663.           15450 S.W. Koll Parkway
  5664.           Beaverton, OR  97006-6063
  5665. X-Phone: (503) 578-4404
  5666. X-Fax: (503) 578-4540
  5667. X-Uucp: ...!uunet!sequent!jaap
  5668. X-Internet: jaap@sequent.com
  5669. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  5670.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  5671.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  5672. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Mon, 10 May 1993 17:49:24 +0200.
  5673.              <9305101749.AA04778=guido@guppie.cwi.nl> 
  5674. Date: Mon, 10 May 1993 11:11:14 -0700
  5675. From: Jaap Vermeulen <jaap@sequent.com>
  5676.  
  5677.  
  5678. | without having to worry about the possibility that you never hit the
  5679. | finally clause.  It is still possible but less likely during normal
  5680.  
  5681. I though you would *always* hit the finally clause, even if you use
  5682. sys.exit()?  (I mean: wasn't this true for the previous version too?)
  5683.  
  5684. | code.  Nobody in their right mind would use posix._exit(n) except to
  5685. | exit from a forked child, but lots of code may call sys.exit(n) -- as
  5686.  
  5687. True, still, os.py is broken on DOS.
  5688.  
  5689. | Code that uses an unqualified except clause is always suspect.  It may
  5690. | mask exceptions caused deep inside that you didn't know were possible,
  5691. | such as SystemError, MemoryError or TypeError in code that you thought
  5692. | had no bugs.
  5693.  
  5694. Yes, I know.  Listing all exceptions I want to catch in separate lines,
  5695. yet all of them using the same code, is a hassle (especially if there
  5696. are quite a few of them).  Couldn't we add something that would allow
  5697. you to pass a list of exception types as the first argument to
  5698. except:?
  5699.  
  5700. Also, the whole stacktrace is a hassle.  It is great for the developer,
  5701. but confusing for the ordinary user that doesn't care for it
  5702. (espacially if the python program is a subprogram of another program).
  5703. That's why often I wrap the whole program in a try: except:,  forgoing
  5704. the stacktrace, but printing the problem (using the exc_type and
  5705. exc_value).
  5706.  
  5707. |     try:
  5708. |         "some code that may raise any exception"
  5709. |     except SystemExit, status:
  5710. |         raise SystemExit, status
  5711. |     except:
  5712. |         "handle any other kind of error"
  5713.  
  5714. Forgot about that one. :-)
  5715.  
  5716. Thanks,
  5717.  
  5718.     -Jaap-
  5719. --
  5720. Jaap Vermeulen                    +--------------------------+
  5721.                         | Sequent Computer Systems |
  5722.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  5723.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  5724. 
  5725. 
  5726. To: Jaap Vermeulen <jaap@sequent.com>
  5727. cc: python-list@cwi.nl
  5728. Subject: Re: SystemExit 
  5729. In-reply-to: Your message of "Mon, 10 May 1993 11:11:14 MDT."
  5730.              <9305101811.AA29028@eng2.sequent.com> 
  5731. From: Guido.van.Rossum@cwi.nl
  5732. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  5733. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  5734. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  5735. Date: Mon, 10 May 1993 20:48:44 +0200
  5736. Sender: guido
  5737.  
  5738. > | without having to worry about the possibility that you never hit the
  5739. > | finally clause.  It is still possible but less likely during normal
  5740. > I though you would *always* hit the finally clause, even if you use
  5741. > sys.exit()?  (I mean: wasn't this true for the previous version too?)
  5742.  
  5743. No, originally sys.exit() would just call the C routine exit().  There
  5744. were complaints about this and I changed it into an exception so that
  5745. finally clauses would work.  (There is no way to execute them except
  5746. by letting the stack unwind itself.)
  5747.  
  5748. Also the exception makes it possible for a debugger or similar package
  5749. to trap sys.exit() without patching up the sys module.
  5750.  
  5751. > | code.  Nobody in their right mind would use posix._exit(n) except to
  5752. > | exit from a forked child, but lots of code may call sys.exit(n) -- as
  5753. > True, still, os.py is broken on DOS.
  5754.  
  5755. Then fix os.py!  (This particular bug will be fixed in the next
  5756. release.)
  5757.  
  5758. Note that os.py also assigns sep = '/' which you probably don't want
  5759. under DOS, although I think it does work; should I fix it?  (I think
  5760. it should also set name = 'dos' or perhaps 'msdos'.)
  5761.  
  5762. Under DOS the _exit() function shouldn't be in os since it isn't in
  5763. the C library either.  (Or is it?  Then maybe I should add it to the
  5764. DOS version of the posix interface...  Please enlighten me, I always
  5765. thought that _exit() is specific to real UNIX and not specified by
  5766. Standard C.)
  5767.  
  5768. > | Code that uses an unqualified except clause is always suspect.  It may
  5769. > | mask exceptions caused deep inside that you didn't know were possible,
  5770. > | such as SystemError, MemoryError or TypeError in code that you thought
  5771. > | had no bugs.
  5772. > Yes, I know.  Listing all exceptions I want to catch in separate lines,
  5773. > yet all of them using the same code, is a hassle (especially if there
  5774. > are quite a few of them).  Couldn't we add something that would allow
  5775. > you to pass a list of exception types as the first argument to
  5776. > except:?
  5777.  
  5778. You can already do this!  (I believe it has always been possible and
  5779. is even documented in the reference manual.)
  5780.  
  5781.     try:
  5782.         "some code"
  5783.     except (ex1, ex2, ex3), value:
  5784.         "handler for three different exceptions"
  5785.  
  5786. > Also, the whole stacktrace is a hassle.  It is great for the developer,
  5787. > but confusing for the ordinary user that doesn't care for it
  5788. > (espacially if the python program is a subprogram of another program).
  5789. > That's why often I wrap the whole program in a try: except:,  forgoing
  5790. > the stacktrace, but printing the problem (using the exc_type and
  5791. > exc_value).
  5792.  
  5793. I would imagine that the vast majority Python scripts are only ever
  5794. run by their author, so having a stack trace by default makes sense.
  5795.  
  5796. If your script is bugfree, it should never print a stack trace.  If it
  5797. does generate an exception, the user can show (or mail) the stack
  5798. trace to the author of the script who can then find the bug.  Printing
  5799. only the exception would make this much harder.  I don't understand
  5800. why you say that the ordinary user doesn't care: the program failed to
  5801. do what it should, so they have every right to complain!
  5802.  
  5803. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5804. 
  5805. 
  5806. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  5807.     id AA20435 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 21:17:12 +0200
  5808. Received: by voorn.cwi.nl with SMTP
  5809.     id AA29134 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 21:17:10 +0200
  5810. Message-Id: <9305101917.AA29134=guido@voorn.cwi.nl>
  5811. To: Jaap Vermeulen <jaap@sequent.com>
  5812. Cc: python-list@cwi.nl
  5813. Subject: Re: Some suggestion for python classes 
  5814. In-Reply-To: Your message of "Mon, 10 May 1993 10:23:59 MDT."
  5815.              <9305101724.AA21460@eng2.sequent.com> 
  5816. From: Guido.van.Rossum@cwi.nl
  5817. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  5818. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  5819. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  5820. Date: Mon, 10 May 1993 21:17:09 +0200
  5821. Sender: Guido.van.Rossum@cwi.nl
  5822.  
  5823. Jaap Vermeulen writes:
  5824.  
  5825. > 1)  When using a class method, it would be nice if the calling class
  5826. >     would be added as the 1st argument of the method.
  5827. >     First let me explain the nomenclature.  A class method is a method
  5828. >     invoked through the class instead of the method.  I.e.
  5829. >     class foo:
  5830. >     def bar():
  5831. >         something
  5832. >     Invoking foo.bar() is invoking a class method.  You could invoke
  5833. >     the same method as a instance method, foo().bar(), however, it
  5834. >     would result in a 'TypeError: arg cound mismatch' since the
  5835. >     instance itself is automatically prepended to the argument list.
  5836. >     What I propose is to do the same when you invoke the method as a
  5837. >     class method, and prepend the class to the method.  This would
  5838. >     result in:
  5839. >     class foo:
  5840. >     def bar(self):
  5841. >         print type(self)
  5842. >     Invoking foo.bar() would result in <type 'class'>, invoking
  5843. >     foo().bar() would result in <type 'instance'>. It is up to the
  5844. >     programmer to correctly code, invoke and identify class method vs.
  5845. >     instance methods (as with a lot of other things in python).
  5846. >     The benefit would be that you can define a class method in a base
  5847. >     class, and still have access to the invoking class. i.e.
  5848. >     class foo:
  5849. >     def new(self):
  5850. >         new_instance = self()
  5851. >         ...
  5852. >         return new_instance
  5853. >     class bar(foo):
  5854. >     ...
  5855. >     Invoking bar.new() would return an instance of bar.  The current
  5856. >     work-around is to invoke the class method as bar.new(bar).
  5857.  
  5858. Ah, but calling a class method is also used in another situation.  The
  5859. standard "idiom" for extending a method is as follows:
  5860.  
  5861.     class Base:
  5862.         def doit(self, how):
  5863.             "do it in a basic way"
  5864.  
  5865.     class Derived(Base):
  5866.         def doit(self, how):
  5867.             "do a little bit in advance"
  5868.             Base.doit(self, how)
  5869.             "do it some more"
  5870.  
  5871. For the interpreter, the call to Base.doit(self, how) in a method of a
  5872. Derived instance is indistinguishable from a call somewhere else.
  5873. This is actually one of the foundations of Python's "cheap"
  5874. implementation of classes and inheritances, and I would hate to lose
  5875. it.  (The point is that the interpreter has no idea that it is
  5876. executing a method -- all it ever sees is function calls.)
  5877.  
  5878. I have a feeling that the only situation where a class method needs to
  5879. know the class from which it was really called is in situations where
  5880. you want to create a new class instance without any reference to
  5881. another.  There is already a standard way to do this, and I don't see
  5882. why "C.new()" is much better than "C().init()" -- the two extra
  5883. parentheses don't really bother me.  If you insist on having a
  5884. function called new() to create class instances, why not make it a
  5885. global function and call it with the class as explicit argument, e.g.
  5886. "new(C)" ?
  5887.  
  5888. But maybe your example is too simplistic to show what the real problem
  5889. is.  What does your new() function do between creating the new
  5890. instance and returning it?  Can't this be done by the instance's
  5891. init() function?
  5892.  
  5893. > 2)  It would be nice to have a special operator to implement the
  5894. >     'super' functionality.  This functionality allows you to start
  5895. >     searching for a method starting at the base classes, not the
  5896. >     current class.  The current workaround is to define a function to
  5897. >     delete the method from the current class (if it's there), retrieve
  5898. >     it using the normal method, and replacing the method in the current
  5899. >     class.  This allows you to write:
  5900. >     class bar(foo):
  5901. >     def new(self):
  5902. >         new_instance = super(self, 'new')(self)
  5903. >         ...
  5904. >         return new_instance
  5905. >     What I would like to see is some special operator that does this
  5906. >     for you, e.g. using a carrot:
  5907. >         new_instance = self^new()
  5908.  
  5909. See my example above of how to extend a method in Python.  The point
  5910. is that the name of the base class is statically known at the point
  5911. where you write the code that needs to use it, so there really is no
  5912. good reason to dynamically look it up -- you might as well use the
  5913. name of the base class.
  5914.  
  5915. You don't give an implementation of your super() workaround -- I have
  5916. a feeling that it might fail if there are several layers of derived
  5917. classes stacked on top of bar and some of them don't define a new()
  5918. method.
  5919.  
  5920. (BTW, I always thought that '^' was called "caret" -- is this a
  5921. special version with night vision? :-)
  5922.  
  5923. > 3)  It would be nice to be able to retrieve the name of a class.  The
  5924. >     attribute exists, but is empty.  I.e. bar.__name__ returns None.
  5925. >     Also, the address operator Guido was talking about would come in
  5926. >     very handy, since you would be able to define something like this
  5927. >     (given that '&' is the address operator):
  5928. >     class bar(foo):
  5929. >     def __repr__(self):
  5930. >         try: return '<class ' + self.__name__ + 'at ' + `&self`
  5931. >         except:
  5932. >         return '<instance ' + self.__class__.__name__ + 'at ' + `&self`
  5933.  
  5934. Yes, this is a bug.  I should fix it.  It's difficult to fix because
  5935. of the way class construction is implemented, but nevertheless I
  5936. should fix it.  BTW, the address-of operator will be called id() and
  5937. return a plain integer.  (Adding unary & would mean a change to the
  5938. grammar, and that's much too drastic for such a little-used function.)
  5939.  
  5940. >     This brings up another point, and that is that __repr__ currently
  5941. >     doesn't work for classes, it would be nice if it did.
  5942.  
  5943. I don't understand how you want it to work.  Do you mean that a class
  5944. should be able to decide how it will be printed?  How would you use
  5945. that?  How would you distinguish between the __repr__ method for
  5946. instances and the one for the class?
  5947.  
  5948. General comments: I have a feeling that you are trying to use classes
  5949. where you should be using instances; this would also explain a few of
  5950. your wishes above.  But again, maybe I'm missing your point -- please
  5951. give more realistic examples to show how you are using all this.
  5952.  
  5953. Your ideas are certainly worth being investigated, it's just that
  5954. everything fits together so tightly that moving one piece usually
  5955. requires moving LOTS of other pieces.  Sometimes at first you don't
  5956. see why a piece is necessary, until you take several steps backwards
  5957. and see the whole structure again...
  5958.  
  5959. Cheers,
  5960.  
  5961. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  5962. 
  5963. 
  5964. Received: from lebe.iaci.kun.nl by charon.cwi.nl with SMTP
  5965.     id AA07615 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 15:08:49 +0200
  5966. Received: by lebe.local (5.57/Ultrix3.0-C)
  5967.     id AA05212; Mon, 10 May 93 15:08:22 +0200
  5968. Message-Id: <9305101308.AA05212@lebe.local>
  5969. To: python-list@cwi.nl
  5970. Subject: python/stdwin/motif
  5971. From: hegt@lebe.iaci.kun.nl
  5972. Date: Mon, 10 May 93 15:08:20 CDT
  5973. Sender: hegt@lebe.local
  5974.  
  5975.  
  5976. Hello all,
  5977.  
  5978. Guido told me, that he is thinking about going to support Motif as the
  5979. underlying window system of Python rather than his own STDWIN.
  5980.  
  5981. I can think of some reasons why this is a good idea, but also why I
  5982. would personally not make this choice:
  5983.  
  5984. - as far as I can see there is not much support for Motif other than as
  5985.   a widget set on top of X11
  5986. - although X11 is available on several platforms, not all of them
  5987.   include Motif, that is for a reasonable price; practically speaking,
  5988.   I think that this means the end of window-based development using
  5989.   Python on non-unix systems
  5990. - what is the purpose a of window-system binding for Python and wouldn't
  5991.   we rather have some portable Xlib level kind of window functionality
  5992.   on all the obvious platforms (mac/pc/unix-x11); we could think of the
  5993.   XVT type of solution, which is more or less an extension of the
  5994.   thoughts behind STDWIN, but developed from the other end, i.e. from
  5995.   existing window systems
  5996.  
  5997. I think that the underlying question is: who is using Python and for
  5998. what? As a newcomer to Python and this list I have no idea about that.
  5999. My own main interest is cross-platform non-standard (so: not MS-Win,
  6000. Motif, OpenLook etc.) GUI prototyping.
  6001.  
  6002. Rob Hegt
  6003. 
  6004. 
  6005. Replied: Tue, 11 May 1993 10:11:43 +0200
  6006. Replied: "John DeGood <degood@lf.hp.com> "
  6007. Received: from hplb.hpl.hp.com by charon.cwi.nl with SMTP
  6008.     id AA22091 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 22:23:16 +0200
  6009. Received: from hpavuu.lf.hp.com by hplb.hpl.hp.com; Mon, 10 May 93 21:16:26 +0100
  6010. Received: by hpavun.lf.hp.com
  6011.     (16.8/15.5+IOS 3.22) id AA14101; Mon, 10 May 93 16:24:32 -0400
  6012. Date: Mon, 10 May 93 16:24:32 -0400
  6013. From: John DeGood <degood@lf.hp.com>
  6014. Message-Id: <9305102024.AA14101@hpavun.lf.hp.com>
  6015. To: guido@cwi.nl
  6016. Subject: Re: python/stdwin/motif
  6017. Cc: python-list@cwi.nl
  6018.  
  6019. > DeskView/X allows you to compile X *CLIENTS* under
  6020. > DOS that talk X. They have Motif libraries also. There are 
  6021. > also a couple others that i have heard about but their names don't
  6022. > jump out at me (since I don't deal with DOS at all..).
  6023.  
  6024. Hummingbird Communications, Ltd (Ontario, Canada) has an X software
  6025. development kit for Microsoft Windows with Xlib, Xt intrinsics, and Xaw
  6026. and Xmu libraries.  They also have an optional OSF/Motif toolkit.  With
  6027. these one can create X Window clients that execute on a PC under
  6028. Microsoft Windows and can be displayed on the local PC X server or on
  6029. any remote PC or Unix system running an X server.
  6030.  
  6031. > One thing I'm thinking of is to create a STDWIN port that uses Motif
  6032. > instead of bare Xlib underneath.  It may even be possible to do this
  6033. > entirely in Python, once my Motif/Xt port has sufficient Xlib
  6034. > functionality (currently it has none).  This would help Rob as well:
  6035. > he can continue to use STDWIN for "toy" apps on his Mac or PC, but on
  6036. > UNIX boxes his apps will follow the Motif style.
  6037.  
  6038. A port to Motif would give STDWIN on Unix a nice facelift.  My
  6039. unfinished Microsoft Windows port of STDWIN uses the Windows style,
  6040. which looks similar to Motif.  So although the current STDWIN-on-Xlib is
  6041. an "ugly duckling" the "toy" platforms already look nice. :-)
  6042.  
  6043. > (To make one thing clear: I don't really plan to discontinue STDWIN,
  6044. > but I don't want to make additions to it either, sice the audience is
  6045. > really too small.  Had there been a Windows port two years ago, the
  6046. > situation might have been different...  Sigh.)
  6047.  
  6048. In these past two years several commercial cross-platform GUI libraries
  6049. have been introduced, but unlike STDWIN they are proprietary and
  6050. expensive.  Even if Motif became "public domain" I don't think it would
  6051. replace STDWIN because only a tiny fraction of PC and Mac users
  6052. currently have the necessary X server software.  So STDWIN may continue
  6053. to be a useful tool for Python cross-platform development for some time.
  6054.  
  6055. John DeGood  degood@lf.hp.com
  6056. Hewlett-Packard Little Falls Site (Wilmington, Delaware)
  6057. 
  6058. 
  6059. Replied: Tue, 11 May 1993 09:23:54 +0200
  6060. Replied: "Jaap Vermeulen <jaap@sequent.com> "
  6061. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  6062.     id AA22978 (5.65b/3.8/CWI-Amsterdam); Mon, 10 May 1993 22:56:38 +0200
  6063. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  6064.     id AA10887; Mon, 10 May 93 13:56:39 -0700
  6065. Received: by eng2.sequent.com (5.65/1.34)
  6066.     id AA18117; Mon, 10 May 93 13:56:29 -0700
  6067. Message-Id: <9305102056.AA18117@eng2.sequent.com>
  6068. To: Guido.van.Rossum@cwi.nl
  6069. Subject: Re: SystemExit
  6070. Priority: Normal
  6071. Precedence: first-class
  6072. Organization: Sequent Computer Systems, Inc.
  6073.           Service Technology - MailStop: WIL2-610
  6074.           15450 S.W. Koll Parkway
  6075.           Beaverton, OR  97006-6063
  6076. X-Phone: (503) 578-4404
  6077. X-Fax: (503) 578-4540
  6078. X-Uucp: ...!uunet!sequent!jaap
  6079. X-Internet: jaap@sequent.com
  6080. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  6081.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  6082.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  6083. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Mon, 10 May 1993 20:48:44 +0200.
  6084.              <9305101848.AA29091=guido@voorn.cwi.nl> 
  6085. Date: Mon, 10 May 1993 13:56:28 -0700
  6086. From: Jaap Vermeulen <jaap@sequent.com>
  6087.  
  6088.  
  6089.  
  6090. I didn't include the list any more since this discussion watered down
  6091. to crossing every T.
  6092.  
  6093. | No, originally sys.exit() would just call the C routine exit().  There
  6094.  
  6095. Ok. issue closed.
  6096.  
  6097. | Then fix os.py!  (This particular bug will be fixed in the next
  6098. | release.)
  6099.  
  6100. Yes, I did and gave you my solution.
  6101.  
  6102. | Note that os.py also assigns sep = '/' which you probably don't want
  6103. | under DOS, although I think it does work; should I fix it?  (I think
  6104. | it should also set name = 'dos' or perhaps 'msdos'.)
  6105.  
  6106. Good idea! I'll send you what I come up with.
  6107.  
  6108. | Under DOS the _exit() function shouldn't be in os since it isn't in
  6109. | the C library either.  (Or is it?  Then maybe I should add it to the
  6110. | DOS version of the posix interface...  Please enlighten me, I always
  6111. | thought that _exit() is specific to real UNIX and not specified by
  6112. | Standard C.)
  6113.  
  6114. I'm not saying it should be there (what does posix mean under msdos?).
  6115. I'm saying that os.py callously tried to include it.
  6116.  
  6117. | > are quite a few of them).  Couldn't we add something that would allow
  6118. | > you to pass a list of exception types as the first argument to
  6119. | > except:?
  6120. | You can already do this!  (I believe it has always been possible and
  6121. | is even documented in the reference manual.)
  6122.  
  6123. You're right, I glanced over the syntax, which doesn't make it clear.
  6124. The next page explains it.  Maybe the syntax could be updated?
  6125. (i.e. from ("except" [condition] ["," target]]... to e.g.
  6126.        ("except" [conditions] ["," target]]...)
  6127.  
  6128. | If your script is bugfree, it should never print a stack trace.  If it
  6129. | does generate an exception, the user can show (or mail) the stack
  6130. | trace to the author of the script who can then find the bug.  Printing
  6131. | only the exception would make this much harder.  I don't understand
  6132.  
  6133. I wouldn't care about the stack trace so much if the format wasn't so
  6134. confusing to the ordinary user (yes, other people than myself are using
  6135. python programs).  Maybe, if the error message could be called out more
  6136. and the stack trace could be preceded with some disclaimer, it wouldn't
  6137. be so confusing to the ordinary user.  They complain to me:  WHAT IS
  6138. HAPPENING??? as where the fault is e.g. disk full or something else
  6139. that I don't check for (is that a bug??? Can't check for everything...)
  6140. and they can't seem to find the actual problem in all the output.
  6141.  
  6142. I'm done whining now. :-)
  6143.  
  6144.     -Jaap-
  6145. --
  6146. Jaap Vermeulen                    +--------------------------+
  6147.                         | Sequent Computer Systems |
  6148.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  6149.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  6150. 
  6151. 
  6152. Replied: Tue, 11 May 1993 11:23:08 +0200
  6153. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list@cwi.nl"
  6154. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  6155.     id AA00978 (5.65b/3.8/CWI-Amsterdam); Tue, 11 May 1993 00:49:29 +0200
  6156. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  6157.     id AA15040; Mon, 10 May 93 15:49:31 -0700
  6158. Received: by eng2.sequent.com (5.65/1.34)
  6159.     id AA03845; Mon, 10 May 93 15:22:45 -0700
  6160. Message-Id: <9305102222.AA03845@eng2.sequent.com>
  6161. To: Guido.van.Rossum@cwi.nl
  6162. Cc: python-list@cwi.nl
  6163. Subject: Re: Some suggestion for python classes
  6164. Priority: Normal
  6165. Precedence: first-class
  6166. Organization: Sequent Computer Systems, Inc.
  6167.           Service Technology - MailStop: WIL2-610
  6168.           15450 S.W. Koll Parkway
  6169.           Beaverton, OR  97006-6063
  6170. X-Phone: (503) 578-4404
  6171. X-Fax: (503) 578-4540
  6172. X-Uucp: ...!uunet!sequent!jaap
  6173. X-Internet: jaap@sequent.com
  6174. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  6175.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  6176.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  6177. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Mon, 10 May 1993 21:17:09 +0200.
  6178.              <9305101917.AA29134=guido@voorn.cwi.nl> 
  6179. Date: Mon, 10 May 1993 15:22:44 -0700
  6180. From: Jaap Vermeulen <jaap@sequent.com>
  6181.  
  6182.  
  6183. | Ah, but calling a class method is also used in another situation.  The
  6184. | standard "idiom" for extending a method is as follows:
  6185. |     class Base:
  6186. |         def doit(self, how):
  6187. |             "do it in a basic way"
  6188. |     class Derived(Base):
  6189. |         def doit(self, how):
  6190. |             "do a little bit in advance"
  6191. |             Base.doit(self, how)
  6192. |             "do it some more"
  6193. | For the interpreter, the call to Base.doit(self, how) in a method of a
  6194. | Derived instance is indistinguishable from a call somewhere else.
  6195.  
  6196. And that exactly illustrates the deficiency for not having a "super"
  6197. operator (I'm jumping ahead to the next issue here), and that is that
  6198. with multiple base classes you have to choose (or *know*) which base
  6199. class to invoke (or write a loop to go through all of them).  That's
  6200. why I prefer a "super" functionality where you let the search algorithm
  6201. find the method (i.e.  it would be nice if I could rewrite the above with):
  6202.  
  6203.         def doit(self, how):
  6204.             "do a little but in advance"
  6205.             self^doit(how)
  6206.             "do it some more"
  6207.  
  6208. I never liked the fact that you have to spell out the base class you're
  6209. invoking from.
  6210.  
  6211. | But maybe your example is too simplistic to show what the real problem
  6212. | is.  What does your new() function do between creating the new
  6213. | instance and returning it?  Can't this be done by the instance's
  6214. | init() function?
  6215.  
  6216. You convinced me that I don't need this functionality.
  6217.  
  6218. [About the "super" operator:]
  6219.  
  6220. | See my example above of how to extend a method in Python.  The point
  6221. | is that the name of the base class is statically known at the point
  6222. | where you write the code that needs to use it, so there really is no
  6223. | good reason to dynamically look it up -- you might as well use the
  6224. | name of the base class.
  6225.  
  6226. Not with multiple base classes.  Besides, you're looking it up
  6227. dynamically anyways (since the method could be way up in the chain).
  6228.  
  6229. | You don't give an implementation of your super() workaround -- I have
  6230. | a feeling that it might fail if there are several layers of derived
  6231. | classes stacked on top of bar and some of them don't define a new()
  6232. | method.
  6233.  
  6234. I don't think so:
  6235.  
  6236. def super(obj, name):
  6237.     if type(obj) == type(object): sym = 'obj.'+name
  6238.     else: sym = 'obj.__class__.'+name
  6239.     
  6240.     try:
  6241.     try:
  6242.         func = eval(sym)
  6243.         exec('del  '+sym)
  6244.         return eval('obj.'+name)
  6245.     finally: exec(sym+'=func')
  6246.     except: return eval('obj.'+name)
  6247.  
  6248. [About aClass.__name__:]
  6249.  
  6250. | I don't understand how you want it to work.  Do you mean that a class
  6251. | should be able to decide how it will be printed?  How would you use
  6252. | that?  How would you distinguish between the __repr__ method for
  6253. | instances and the one for the class?
  6254.  
  6255. Let me rephrase this:  Currently what the repr() prints out is of
  6256. little use to see what it is.  It would be *much* nicer, and of much
  6257. more use if the name could be included in the default representation,
  6258. both for classes and instances.
  6259.  
  6260.     -Jaap-
  6261. --
  6262. Jaap Vermeulen                    +--------------------------+
  6263.                         | Sequent Computer Systems |
  6264.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  6265.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  6266. 
  6267. 
  6268. To: Jaap Vermeulen <jaap@sequent.com>
  6269. Subject: Re: SystemExit 
  6270. In-reply-to: Your message of "Mon, 10 May 1993 13:56:28 MDT."
  6271.              <9305102056.AA18117@eng2.sequent.com> 
  6272. From: Guido.van.Rossum@cwi.nl
  6273. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  6274. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  6275. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6276. Date: Tue, 11 May 1993 09:23:55 +0200
  6277. Sender: guido
  6278.  
  6279. > | Under DOS the _exit() function shouldn't be in os since it isn't in
  6280. > | the C library either.  (Or is it?  Then maybe I should add it to the
  6281. > | DOS version of the posix interface...  Please enlighten me, I always
  6282. > | thought that _exit() is specific to real UNIX and not specified by
  6283. > | Standard C.)
  6284. > I'm not saying it should be there (what does posix mean under msdos?).
  6285. > I'm saying that os.py callously tried to include it.
  6286.  
  6287. I got that, but I failed (and still fail) to see what pertinence a bug
  6288. in os.py has to do with the semantics of sys.exit()...  Let's drop
  6289. this silly argument, OK!
  6290.  
  6291. > I wouldn't care about the stack trace so much if the format wasn't so
  6292. > confusing to the ordinary user (yes, other people than myself are using
  6293. > python programs).  Maybe, if the error message could be called out more
  6294. > and the stack trace could be preceded with some disclaimer, it wouldn't
  6295. > be so confusing to the ordinary user.  They complain to me:  WHAT IS
  6296. > HAPPENING??? as where the fault is e.g. disk full or something else
  6297. > that I don't check for (is that a bug??? Can't check for everything...)
  6298. > and they can't seem to find the actual problem in all the output.
  6299.  
  6300. Excuse me, but it's obvious that the bug is in your program.  (Half
  6301. :-)  Read any good, recent book on user interfaces and you'll find that
  6302. it is unacceptable for users if a program fails with a cryptic error
  6303. message.  I bet that a short cryptic error message (just the exception
  6304. name) isn't any better than a long one (which includes the stack
  6305. trace) since in both cases it's communicating at the wrong level, as
  6306. far as the user is concerned.  (And note that a C program would
  6307. probably have failed silently in the case of disk full, unless there
  6308. was an explicit check at every write call!  Do you like that better?)
  6309.  
  6310. However, I should take my part of the blame too: it is true that when
  6311. the stack trace is long the exception type is hard to find.  I'll
  6312. experiment with placing the exception message *after* the stack trace
  6313. instead of before it.
  6314.  
  6315. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6316. 
  6317. 
  6318. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  6319.     id AA04330 (5.65b/3.8/CWI-Amsterdam); Tue, 11 May 1993 11:23:09 +0200
  6320. Received: by voorn.cwi.nl with SMTP
  6321.     id AA00423 (5.65b/3.8/CWI-Amsterdam); Tue, 11 May 1993 11:23:09 +0200
  6322. Message-Id: <9305110923.AA00423=guido@voorn.cwi.nl>
  6323. To: Jaap Vermeulen <jaap@sequent.com>
  6324. Cc: python-list@cwi.nl
  6325. Subject: Re: Some suggestion for python classes 
  6326. In-Reply-To: Your message of "Mon, 10 May 1993 15:22:44 MDT."
  6327.              <9305102222.AA03845@eng2.sequent.com> 
  6328. From: Guido.van.Rossum@cwi.nl
  6329. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  6330. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  6331. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6332. Date: Tue, 11 May 1993 11:23:09 +0200
  6333. Sender: Guido.van.Rossum@cwi.nl
  6334.  
  6335. Jaap Vermeulen writes:
  6336. > And that exactly illustrates the deficiency for not having a "super"
  6337. > operator (I'm jumping ahead to the next issue here), and that is that
  6338. > with multiple base classes you have to choose (or *know*) which base
  6339. > class to invoke (or write a loop to go through all of them).  That's
  6340. > why I prefer a "super" functionality where you let the search algorithm
  6341. > find the method (i.e.  it would be nice if I could rewrite the above with):
  6342. >         def doit(self, how):
  6343. >             "do a little but in advance"
  6344. >             self^doit(how)
  6345. >             "do it some more"
  6346. > I never liked the fact that you have to spell out the base class you're
  6347. > invoking from.
  6348.  
  6349. Apart from personal likes and dislikes, I agree that sometimes it is a
  6350. nuisance having to spell out the name of the base class (especially if
  6351. it happens to have the form VeryLongModuleName.EvenLongerClassName :-).
  6352. But this is no more than a nuisance.
  6353.  
  6354. However, bringing in multiple inheritance changes the matter.  (In
  6355. fact, in a totally different context, I remember having implemented
  6356. exactly this kind of functionality: "give me the object named X that
  6357. would be used if there wasn't an X defined locally".)  I would still
  6358. maintain that if you don't know which base class's X you are
  6359. overriding you are in trouble (i.e. you don't know a basic fact about
  6360. the code you are using), but I agree that extending a method deserves
  6361. some special facility.
  6362.  
  6363. I would like to find a way that doesn't need new syntax.  Other
  6364. requirements are that it should be reasonably compact to write down,
  6365. it shouldn't require you to quote the attribute name, it shouldn't
  6366. pollute the instance's name space, nor should it use underscores to
  6367. avoid namespace pollution.  How about a built-in function "super"
  6368. which returns a pseudo object whose name space is that of its argument
  6369. except that the derived class is stripped?  So you would be able to
  6370. write super(self).doit(how).  (Adding a new built-in function is also
  6371. a form of namespace pollution, but causes fewer conflicts and no
  6372. backward compatibility problems since user-defined global and local
  6373. names have priority over built-in functions.)
  6374.  
  6375. {I now do believe that your implementation of super works.]
  6376.  
  6377. > Let me rephrase this:  Currently what the repr() prints out is of
  6378. > little use to see what it is.  It would be *much* nicer, and of much
  6379. > more use if the name could be included in the default representation,
  6380. > both for classes and instances.
  6381.  
  6382. This will be fixed for classes when I fix the __name__ attribute.  For
  6383. instances, I don't see how it can be fixed, since instances don't have
  6384. names when they are created.  (If you write "x = C().init()", the
  6385. instance's name is *not* x -- all of Python's assignment semantics are
  6386. based on this fact...)
  6387.  
  6388. Cheers,
  6389.  
  6390. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6391. 
  6392. 
  6393. To: Jaap Vermeulen <jaap@sequent.com>
  6394. cc: python-list@cwi.nl
  6395. Subject: Re: Some suggestion for python classes 
  6396. In-reply-to: Your message of "Mon, 10 May 1993 15:22:44 MDT."
  6397.              <9305102222.AA03845@eng2.sequent.com> 
  6398. From: Guido.van.Rossum@cwi.nl
  6399. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  6400. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  6401. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6402. Date: Tue, 11 May 1993 11:23:09 +0200
  6403. Sender: guido
  6404.  
  6405. Jaap Vermeulen writes:
  6406. > And that exactly illustrates the deficiency for not having a "super"
  6407. > operator (I'm jumping ahead to the next issue here), and that is that
  6408. > with multiple base classes you have to choose (or *know*) which base
  6409. > class to invoke (or write a loop to go through all of them).  That's
  6410. > why I prefer a "super" functionality where you let the search algorithm
  6411. > find the method (i.e.  it would be nice if I could rewrite the above with):
  6412. >         def doit(self, how):
  6413. >             "do a little but in advance"
  6414. >             self^doit(how)
  6415. >             "do it some more"
  6416. > I never liked the fact that you have to spell out the base class you're
  6417. > invoking from.
  6418.  
  6419. Apart from personal likes and dislikes, I agree that sometimes it is a
  6420. nuisance having to spell out the name of the base class (especially if
  6421. it happens to have the form VeryLongModuleName.EvenLongerClassName :-).
  6422. But this is no more than a nuisance.
  6423.  
  6424. However, bringing in multiple inheritance changes the matter.  (In
  6425. fact, in a totally different context, I remember having implemented
  6426. exactly this kind of functionality: "give me the object named X that
  6427. would be used if there wasn't an X defined locally".)  I would still
  6428. maintain that if you don't know which base class's X you are
  6429. overriding you are in trouble (i.e. you don't know a basic fact about
  6430. the code you are using), but I agree that extending a method deserves
  6431. some special facility.
  6432.  
  6433. I would like to find a way that doesn't need new syntax.  Other
  6434. requirements are that it should be reasonably compact to write down,
  6435. it shouldn't require you to quote the attribute name, it shouldn't
  6436. pollute the instance's name space, nor should it use underscores to
  6437. avoid namespace pollution.  How about a built-in function "super"
  6438. which returns a pseudo object whose name space is that of its argument
  6439. except that the derived class is stripped?  So you would be able to
  6440. write super(self).doit(how).  (Adding a new built-in function is also
  6441. a form of namespace pollution, but causes fewer conflicts and no
  6442. backward compatibility problems since user-defined global and local
  6443. names have priority over built-in functions.)
  6444.  
  6445. {I now do believe that your implementation of super works.]
  6446.  
  6447. > Let me rephrase this:  Currently what the repr() prints out is of
  6448. > little use to see what it is.  It would be *much* nicer, and of much
  6449. > more use if the name could be included in the default representation,
  6450. > both for classes and instances.
  6451.  
  6452. This will be fixed for classes when I fix the __name__ attribute.  For
  6453. instances, I don't see how it can be fixed, since instances don't have
  6454. names when they are created.  (If you write "x = C().init()", the
  6455. instance's name is *not* x -- all of Python's assignment semantics are
  6456. based on this fact...)
  6457.  
  6458. Cheers,
  6459.  
  6460. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6461. 
  6462. 
  6463. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  6464.     id AA23025 (5.65b/3.8/CWI-Amsterdam); Tue, 11 May 1993 21:01:26 +0200
  6465. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  6466.     id AA19086; Tue, 11 May 93 12:01:21 -0700
  6467. Received: by eng2.sequent.com (5.65/1.34)
  6468.     id AA21832; Tue, 11 May 93 12:01:12 -0700
  6469. Message-Id: <9305111901.AA21832@eng2.sequent.com>
  6470. To: Guido.van.Rossum@cwi.nl
  6471. Cc: python-list@cwi.nl
  6472. Subject: Re: Some suggestion for python classes
  6473. Priority: Normal
  6474. Precedence: first-class
  6475. Organization: Sequent Computer Systems, Inc.
  6476.           Service Technology - MailStop: WIL2-610
  6477.           15450 S.W. Koll Parkway
  6478.           Beaverton, OR  97006-6063
  6479. X-Phone: (503) 578-4404
  6480. X-Fax: (503) 578-4540
  6481. X-Uucp: ...!uunet!sequent!jaap
  6482. X-Internet: jaap@sequent.com
  6483. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  6484.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  6485.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  6486. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Tue, 11 May 1993 11:23:09 +0200.
  6487.              <9305110923.AA00423=guido@voorn.cwi.nl> 
  6488. Date: Tue, 11 May 93 12:01:10 PDT
  6489. From: Jaap Vermeulen <jaap@sequent.com>
  6490.  
  6491.  
  6492. | write super(self).doit(how).  (Adding a new built-in function is also
  6493.  
  6494. That would be fine. Thanks.
  6495.  
  6496. | This will be fixed for classes when I fix the __name__ attribute.  For
  6497. | instances, I don't see how it can be fixed, since instances don't have
  6498. | names when they are created.  (If you write "x = C().init()", the
  6499.  
  6500. I was thinking about prepending the name with 'class' or 'instance',
  6501. but I can do without the instance name just fine (since I can override
  6502. it).
  6503.  
  6504. As an example:
  6505.  
  6506. >>> class foo: pass
  6507.  
  6508. >>> foo
  6509. <class foo at 63a08>
  6510. >>> foo()
  6511. <instance foo at 83948>
  6512. >>>
  6513.  
  6514. Thanks,
  6515.  
  6516.     -Jaap-
  6517. --
  6518. Jaap Vermeulen                    +--------------------------+
  6519.                         | Sequent Computer Systems |
  6520.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  6521.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  6522. 
  6523. 
  6524. Replied: Wed, 12 May 1993 08:55:25 +0200
  6525. Replied: "Lance Ellinghouse <lance@markv.com> python-list@cwi.nl"
  6526. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  6527.     id AA04375 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 00:48:20 +0200
  6528. From: Lance Ellinghouse <lance@markv.com>
  6529. X-Mailer: SCO System V Mail (version 3.2)
  6530. To: python-list@cwi.nl
  6531. Subject: MD5 module...
  6532. Date: Tue, 11 May 93 15:45:42 PDT
  6533. Message-Id:  <9305111545.aa16801@hermix.markv.com>
  6534.  
  6535. Where can I get the files needed to support the MD5 module?
  6536. I have the MPZ files from GNU but cannot find the MD5 files..:(
  6537.  
  6538. Anyone have any ideas??
  6539.  
  6540. Can anyone FTP them to me? 
  6541.  
  6542. Thanks,
  6543. Lance Ellinghouse
  6544. lance@markv.com
  6545. 
  6546. 
  6547. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  6548.     id AA29308 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 08:55:29 +0200
  6549. Received: by voorn.cwi.nl with SMTP
  6550.     id AA03307 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 08:55:25 +0200
  6551. Message-Id: <9305120655.AA03307=guido@voorn.cwi.nl>
  6552. To: Lance Ellinghouse <lance@markv.com>
  6553. Cc: python-list@cwi.nl
  6554. Subject: Re: MD5 module... 
  6555. In-Reply-To: Your message of "Tue, 11 May 1993 15:45:42 MDT."
  6556.              <9305111545.aa16801@hermix.markv.com> 
  6557. From: Guido.van.Rossum@cwi.nl
  6558. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  6559. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  6560. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6561. Date: Wed, 12 May 1993 08:55:25 +0200
  6562. Sender: Guido.van.Rossum@cwi.nl
  6563.  
  6564. > Where can I get the files needed to support the MD5 module?
  6565. > I have the MPZ files from GNU but cannot find the MD5 files..:(
  6566. > Anyone have any ideas??
  6567. > Can anyone FTP them to me? 
  6568.  
  6569. >From the Makefile (I agree not a perfect place to look for an ftp
  6570. pointer :-):
  6571.  
  6572. # This option enables access to the RSA Data Security, Inc. MD5
  6573. # Message-Digest Algorithm.  This requires the files md5.c and md5.h
  6574. # which are included in the file md5.doc ftp'able from rsa.com.
  6575.  
  6576. BTW there's a new MPZ out -- anyone care to test it out?  (I have
  6577. little time nor a direct need for it...)
  6578.  
  6579. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6580. 
  6581. 
  6582. To: Lance Ellinghouse <lance@markv.com>
  6583. cc: python-list@cwi.nl
  6584. Subject: Re: MD5 module... 
  6585. In-reply-to: Your message of "Tue, 11 May 1993 15:45:42 MDT."
  6586.              <9305111545.aa16801@hermix.markv.com> 
  6587. From: Guido.van.Rossum@cwi.nl
  6588. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  6589. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  6590. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6591. Date: Wed, 12 May 1993 08:55:25 +0200
  6592. Sender: guido
  6593.  
  6594. > Where can I get the files needed to support the MD5 module?
  6595. > I have the MPZ files from GNU but cannot find the MD5 files..:(
  6596. > Anyone have any ideas??
  6597. > Can anyone FTP them to me? 
  6598.  
  6599. From the Makefile (I agree not a perfect place to look for an ftp
  6600. pointer :-):
  6601.  
  6602. # This option enables access to the RSA Data Security, Inc. MD5
  6603. # Message-Digest Algorithm.  This requires the files md5.c and md5.h
  6604. # which are included in the file md5.doc ftp'able from rsa.com.
  6605.  
  6606. BTW there's a new MPZ out -- anyone care to test it out?  (I have
  6607. little time nor a direct need for it...)
  6608.  
  6609. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6610. 
  6611. 
  6612. Received: from att-out.att.com by charon.cwi.nl with SMTP
  6613.     id AA00763 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 09:20:22 +0200
  6614. From: hzsbg01!jbuhrma@hvgtw.att.com
  6615. Received: from hzsbc03 by hzsbg01 (4.1/SMI-4.1)
  6616.     id AA09850; Wed, 12 May 93 09:16:58 +0200
  6617. Date: Wed, 12 May 93 09:16:58 +0200
  6618. Original-From: hzsbg01!jbuhrma
  6619. Message-Id: <9305120716.AA09850@hzsbg01>
  6620. To: lance@markv.com
  6621. Subject: Re: MD5 module...
  6622. Cc: python-list@cwi.nl
  6623.  
  6624. > Where can I get the files needed to support the MD5 module?
  6625. > I have the MPZ files from GNU but cannot find the MD5 files..:(
  6626.  
  6627. You can ftp it from `rsa.com'.  The file is called `md5.doc'.
  6628.  
  6629. You'll have to extract the C-sources from this document.  The sources
  6630. also contain a test program; the output from this test program should be
  6631. exact the same as the output from the Python md5 test program.
  6632.  
  6633. Regards,
  6634.  
  6635. -- Jan-Hein Buhrman -- AT&T Huizen NL -- <jbuhrma%hzsbg01@hvlpa.att.com> --
  6636. ---------------------- +31 35 87.4278 --- ...!att!hvlpa!hzsbg01!jbuhrma ---
  6637. usage: prog [option(s)] [--] [arg(s) ...]
  6638. 
  6639. 
  6640. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  6641.     id AA01455 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 09:33:14 +0200
  6642. Received: by voorn.cwi.nl with SMTP
  6643.     id AA03463 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 09:33:13 +0200
  6644. Message-Id: <9305120733.AA03463=guido@voorn.cwi.nl>
  6645. To: python-list@cwi.nl
  6646. Subject: Oops, super() can't work!
  6647. From: Guido.van.Rossum@cwi.nl
  6648. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  6649. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6650. Date: Wed, 12 May 1993 09:33:13 +0200
  6651. Sender: Guido.van.Rossum@cwi.nl
  6652.  
  6653. I had a hunch about Jaap's super() method that it wouldn't work with
  6654. multiple nested levels of extending the same method.  Now I have
  6655. proof.  The problem occurs when A is a base class of B and B
  6656. is a base class of C, and each of B and C have a method with the same
  6657. name that extends their base class's version.  Now if we have an
  6658. instance of C, the C version will call the B version alright, but the
  6659. call to super() in the B version will not retrieve the A version of
  6660. the method -- it will retrieve the B version again.  This is because
  6661. even during execution of the B method, the type of self is still C.
  6662. See example after my signature.
  6663.  
  6664. A built-in super() function would have the same problem -- the
  6665. information about the current class is simply not available (and
  6666. Python's dynamic object model makes it even possible to have a
  6667. function being included as a method in two different classes!).
  6668.  
  6669. So I'll have to resort to my gut feeling about this: if you don't know
  6670. which base class's method you're overriding you don't know what you're
  6671. doing!
  6672.  
  6673. The only way to fix this would be to make the interpreter aware of the
  6674. class to which a method belongs, which would require a major
  6675. reorganization of the interpreter and code generator.  How does
  6676. Smalltalk do this?  I know that Simula has a "super" construct in the
  6677. language but there it is solved at compile time.  In C++ you have to
  6678. name the base class explicitly, as in Python.  I believe it's the same
  6679. in Modula-3 (from which I borrowed more than one idea for Python).
  6680.  
  6681. My only hope is that perhaps Steve Myale of U of Virginia has already
  6682. fixed this in his mods to eliminate self and introduce private and
  6683. public variables (and much more).  Steve?  (We'll need to discuss your
  6684. changes to the language on the list anyway, before they can become an
  6685. official part of it.)
  6686.  
  6687. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6688.  
  6689. ========================================================================
  6690. class A:
  6691.     def meth(self):
  6692.         print 'A.self(', self, ')'
  6693.  
  6694. class B(A):
  6695.     def meth(self):
  6696.         print 'B.self(', self, ')'
  6697.         super(self, 'meth')()
  6698.  
  6699. class C(B):
  6700.     def meth(self):
  6701.         print 'C.self(', self, ')'
  6702.         super(self, 'meth')()
  6703.  
  6704. def super(obj, name):
  6705.     # Simplified version of Jaap's super(), for instances only!
  6706.     sym = 'obj.'+name
  6707.  
  6708.     try:
  6709.         try:
  6710.             func = eval(sym)
  6711.             exec('del  '+sym)
  6712.             return eval('obj.'+name)
  6713.         finally:
  6714.             exec(sym+'=func')
  6715.     except:
  6716.         return eval('obj.'+name)
  6717.  
  6718. print 'test A:'
  6719. a = A()
  6720. a.meth()
  6721.  
  6722. print 'test B:'
  6723. b = B()
  6724. b.meth()
  6725.  
  6726. print 'test C:'
  6727. c = C()
  6728. c.meth()
  6729. ========================================================================
  6730. test A:
  6731. A.self( <instance object at 100e74d0> )
  6732. test B:
  6733. B.self( <instance object at 100e74b0> )
  6734. B.self( <instance object at 100e74b0> )
  6735. B.self( <instance object at 100e74b0> )
  6736. B.self( <instance object at 100e74b0> )
  6737. .
  6738. .
  6739. .
  6740. 
  6741. 
  6742. To: python-list
  6743. Subject: Oops, super() can't work!
  6744. From: Guido.van.Rossum@cwi.nl
  6745. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  6746. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6747. Date: Wed, 12 May 1993 09:33:13 +0200
  6748. Sender: guido
  6749.  
  6750. I had a hunch about Jaap's super() method that it wouldn't work with
  6751. multiple nested levels of extending the same method.  Now I have
  6752. proof.  The problem occurs when A is a base class of B and B
  6753. is a base class of C, and each of B and C have a method with the same
  6754. name that extends their base class's version.  Now if we have an
  6755. instance of C, the C version will call the B version alright, but the
  6756. call to super() in the B version will not retrieve the A version of
  6757. the method -- it will retrieve the B version again.  This is because
  6758. even during execution of the B method, the type of self is still C.
  6759. See example after my signature.
  6760.  
  6761. A built-in super() function would have the same problem -- the
  6762. information about the current class is simply not available (and
  6763. Python's dynamic object model makes it even possible to have a
  6764. function being included as a method in two different classes!).
  6765.  
  6766. So I'll have to resort to my gut feeling about this: if you don't know
  6767. which base class's method you're overriding you don't know what you're
  6768. doing!
  6769.  
  6770. The only way to fix this would be to make the interpreter aware of the
  6771. class to which a method belongs, which would require a major
  6772. reorganization of the interpreter and code generator.  How does
  6773. Smalltalk do this?  I know that Simula has a "super" construct in the
  6774. language but there it is solved at compile time.  In C++ you have to
  6775. name the base class explicitly, as in Python.  I believe it's the same
  6776. in Modula-3 (from which I borrowed more than one idea for Python).
  6777.  
  6778. My only hope is that perhaps Steve Myale of U of Virginia has already
  6779. fixed this in his mods to eliminate self and introduce private and
  6780. public variables (and much more).  Steve?  (We'll need to discuss your
  6781. changes to the language on the list anyway, before they can become an
  6782. official part of it.)
  6783.  
  6784. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6785.  
  6786. ========================================================================
  6787. class A:
  6788.     def meth(self):
  6789.         print 'A.self(', self, ')'
  6790.  
  6791. class B(A):
  6792.     def meth(self):
  6793.         print 'B.self(', self, ')'
  6794.         super(self, 'meth')()
  6795.  
  6796. class C(B):
  6797.     def meth(self):
  6798.         print 'C.self(', self, ')'
  6799.         super(self, 'meth')()
  6800.  
  6801. def super(obj, name):
  6802.     # Simplified version of Jaap's super(), for instances only!
  6803.     sym = 'obj.'+name
  6804.  
  6805.     try:
  6806.         try:
  6807.             func = eval(sym)
  6808.             exec('del  '+sym)
  6809.             return eval('obj.'+name)
  6810.         finally:
  6811.             exec(sym+'=func')
  6812.     except:
  6813.         return eval('obj.'+name)
  6814.  
  6815. print 'test A:'
  6816. a = A()
  6817. a.meth()
  6818.  
  6819. print 'test B:'
  6820. b = B()
  6821. b.meth()
  6822.  
  6823. print 'test C:'
  6824. c = C()
  6825. c.meth()
  6826. ========================================================================
  6827. test A:
  6828. A.self( <instance object at 100e74d0> )
  6829. test B:
  6830. B.self( <instance object at 100e74b0> )
  6831. B.self( <instance object at 100e74b0> )
  6832. B.self( <instance object at 100e74b0> )
  6833. B.self( <instance object at 100e74b0> )
  6834. .
  6835. .
  6836. .
  6837. 
  6838. 
  6839. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  6840.     id AA08135 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 12:48:25 +0200
  6841. Received: by voorn.cwi.nl with SMTP
  6842.     id AA04360 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 12:48:24 +0200
  6843. Message-Id: <9305121048.AA04360=guido@voorn.cwi.nl>
  6844. To: python-list@cwi.nl
  6845. Subject: continuation lines
  6846. From: Guido.van.Rossum@cwi.nl
  6847. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  6848. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  6849. Date: Wed, 12 May 1993 12:48:23 +0200
  6850. Sender: Guido.van.Rossum@cwi.nl
  6851.  
  6852. Someone gave me a tiny mod (about 15 lines) to the tokenizer that
  6853. makes breaking long lines easier.  The mod makes it possible to omit
  6854. the backslash when breaking a line *inside parentheses*.  The mod
  6855. keeps track of the accumulated nesting level of all sorts of
  6856. parentheses: () [] {}, and suppresses the NEWLINE token (and the check
  6857. for indentation level)when the parentheses nesting level is greater
  6858. than zero.  It relies on the parser to make sure that parentheses
  6859. occur in properly matched pairs and at syntactically legal places.
  6860.  
  6861. The net effect is that you can write things like
  6862.  
  6863.     function_with_many_arguments(the_first_argument,
  6864.                      the_second_argument,
  6865.                      the_third_argument,
  6866.                      the_fourth_argument,
  6867.                      the_last_argument)
  6868.  
  6869. or initialize lists as follows:
  6870.  
  6871.     months = ['Jan', 'Feb', 'Mar',    # first Q
  6872.           'Apr', 'May', 'Jun',    # second Q
  6873.           'Jul', 'Aug', 'Sep',    # third Q
  6874.           'Oct', 'Nov', 'Dec']    # fourth Q
  6875.  
  6876. (Code using backslashes still works, but note that a line can't have a
  6877. backslash *and* a comment, so there's a definite improvement here.)
  6878.  
  6879. A drawback is that if you accidentally forget a closing parenthesis,
  6880. you might get a syntax error on the next line or even further down.
  6881. Usually this will be on the first token of the next line though (since
  6882. most tokens that can start a statement can't continue an expression --
  6883. the exception being open parentheses and brackets).  A way to
  6884. alleviate this problem would be to print the entire current *logical*
  6885. line when a syntax error has occurred.
  6886.  
  6887. Ideally, one would like a syntax where a line can be broken without a
  6888. backslash anywhere where the syntax doesn't allow a newline token.
  6889. This would allow things like
  6890.  
  6891.     if very_long_condition and _another_long_condition and
  6892.             yet_another_condition and another_one_again:
  6893.         do_something_very_carefully()
  6894.  
  6895. and
  6896.  
  6897.     a_variable_with_an_excruciatingly_long_identifier =
  6898.         an_expression_that_is_almost_equally_horrible
  6899.     
  6900.  
  6901. (but still not this:
  6902.  
  6903.     print 1, 2, 3,
  6904.           4, 5, 6
  6905.  
  6906. nor
  6907.  
  6908.     x = 1, 2, 3,
  6909.         4, 5, 6
  6910.  
  6911. -- do you see why not?)
  6912.  
  6913. However, such a change would require a much bigger change to the
  6914. parser and tokenizer (apart from the difficulties in spelling out
  6915. *exactly* what the rules would be, for future generations).
  6916.  
  6917. I feel that this mod would be a useful addition to Python (also it
  6918. fits nicely in the tradition of carefully trading certain principles
  6919. for implementability).
  6920.  
  6921. What do you think?
  6922.  
  6923. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  6924. 
  6925. 
  6926. Received: from relay.surfnet.nl by charon.cwi.nl with SMTP
  6927.     id AA08710 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 13:16:43 +0200
  6928. X400-Received: by mta relay.surfnet.nl in /PRMD=surf/ADMD=400net/C=nl/; Relayed;
  6929.                Wed, 12 May 1993 13:16:00 +0200
  6930. X400-Received: by /PRMD=surf/ADMD=400net/C=nl/; Relayed;
  6931.                Wed, 12 May 1993 13:17:24 +0200
  6932. X400-Received: by /PRMD=uk.ac/ADMD= /C=gb/; Relayed;
  6933.                Wed, 12 May 1993 13:15:15 +0200
  6934. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  6935.                Wed, 12 May 1993 13:15:03 +0200
  6936. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  6937.                Wed, 12 May 1993 13:14:52 +0200
  6938. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  6939.                Wed, 12 May 1993 13:14:52 +0200
  6940. Date: Wed, 12 May 1993 13:14:52 +0200
  6941. X400-Originator: peter%robots.oxford.ac.uk@prg.oxford.ac.uk
  6942. X400-Recipients: Guido.van.Rossum@cwi.nl
  6943. X400-Mts-Identifier: [/PRMD=UK.AC/ADMD= /C=GB/;<9305121114.AA08646@moth.robots.]
  6944. X400-Content-Type: P2-1984 (2)
  6945. Content-Identifier: Re: continuat...
  6946. From: peter@robots.oxford.ac.uk
  6947. Message-Id: <9305121114.AA08646@moth.robots.ox.ac.uk>
  6948. To: Guido.van.Rossum@cwi.nl
  6949. Subject: Re: continuation lines
  6950.  
  6951. It seems much nicer to have your proposed change, instead of typing backslash
  6952. each time.  But I think that having a better error report may (_slightly_)
  6953. outweigh the pain of backslashing.  It's a very marginal decision -- maybe
  6954. just toss a coin :-)
  6955.  
  6956. Pete.
  6957. 
  6958. 
  6959. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  6960.     id AA16642 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 17:44:05 +0200
  6961. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  6962.     id AA27808; Wed, 12 May 93 08:44:07 -0700
  6963. Received: by eng2.sequent.com (5.65/1.34)
  6964.     id AA03222; Wed, 12 May 93 08:44:01 -0700
  6965. Message-Id: <9305121544.AA03222@eng2.sequent.com>
  6966. To: Guido.van.Rossum@cwi.nl
  6967. Cc: python-list@cwi.nl
  6968. Subject: Re: continuation lines
  6969. Priority: Normal
  6970. Precedence: first-class
  6971. Organization: Sequent Computer Systems, Inc.
  6972.           Service Technology - MailStop: WIL2-610
  6973.           15450 S.W. Koll Parkway
  6974.           Beaverton, OR  97006-6063
  6975. X-Phone: (503) 578-4404
  6976. X-Fax: (503) 578-4540
  6977. X-Uucp: ...!uunet!sequent!jaap
  6978. X-Internet: jaap@sequent.com
  6979. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  6980.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  6981.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  6982. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Wed, 12 May 1993 12:48:23 +0200.
  6983.              <9305121048.AA04360=guido@voorn.cwi.nl> 
  6984. Date: Wed, 12 May 1993 08:44:00 -0700
  6985. From: Jaap Vermeulen <jaap@sequent.com>
  6986.  
  6987.  
  6988. | What do you think?
  6989.  
  6990. I think that is great, because I already ran into the inconvenience of
  6991. the backslash notation.  Most long lines are within parenthesis, so the
  6992. mod it very useful!
  6993.  
  6994.     -Jaap-
  6995. --
  6996. Jaap Vermeulen                    +--------------------------+
  6997.                         | Sequent Computer Systems |
  6998.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  6999.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  7000. 
  7001. 
  7002. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  7003.     id AA16837 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 17:52:51 +0200
  7004. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  7005.     id AA28300; Wed, 12 May 93 08:52:50 -0700
  7006. Received: by eng2.sequent.com (5.65/1.34)
  7007.     id AA04404; Wed, 12 May 93 08:52:40 -0700
  7008. Message-Id: <9305121552.AA04404@eng2.sequent.com>
  7009. To: Guido.van.Rossum@cwi.nl
  7010. Cc: python-list@cwi.nl
  7011. Subject: Re: Oops, super() can't work!
  7012. Priority: Normal
  7013. Precedence: first-class
  7014. Organization: Sequent Computer Systems, Inc.
  7015.           Service Technology - MailStop: WIL2-610
  7016.           15450 S.W. Koll Parkway
  7017.           Beaverton, OR  97006-6063
  7018. X-Phone: (503) 578-4404
  7019. X-Fax: (503) 578-4540
  7020. X-Uucp: ...!uunet!sequent!jaap
  7021. X-Internet: jaap@sequent.com
  7022. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  7023.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  7024.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  7025. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Wed, 12 May 1993 09:33:13 +0200.
  7026.              <9305120733.AA03463=guido@voorn.cwi.nl> 
  7027. Date: Wed, 12 May 1993 08:52:38 -0700
  7028. From: Jaap Vermeulen <jaap@sequent.com>
  7029.  
  7030.  
  7031. | name that extends their base class's version.  Now if we have an
  7032. | instance of C, the C version will call the B version alright, but the
  7033. | call to super() in the B version will not retrieve the A version of
  7034. | the method -- it will retrieve the B version again.  This is because
  7035. | even during execution of the B method, the type of self is still C.
  7036.  
  7037. Damn!  You're right.  What a drag.  The only thing you could try to do
  7038. is matching the actual code object, but that becomes a kludge.
  7039.  
  7040. | reorganization of the interpreter and code generator.  How does
  7041. | Smalltalk do this?  I know that Simula has a "super" construct in the
  7042.  
  7043. No idea.  But Smalltalk is inherently organized and structured
  7044. differently.
  7045.  
  7046. | My only hope is that perhaps Steve Myale of U of Virginia has already
  7047. | fixed this in his mods to eliminate self and introduce private and
  7048. | public variables (and much more).  Steve?  (We'll need to discuss your
  7049. | changes to the language on the list anyway, before they can become an
  7050. | official part of it.)
  7051.  
  7052. I would like to see a proposal for these changes. I'm very much interested.
  7053.  
  7054. I guess the bottom line of this discussion is:
  7055.  
  7056. Some of my proposed changes would have been nice and transparent to the
  7057. programmer, however, I'm sure I can live without.  I'll soon be
  7058. implementing another piece of code using classes extensively, so,
  7059. again, I'll try to gauge how well Python is holding up!
  7060.  
  7061. Thanks for this discussion,
  7062.  
  7063.     -Jaap-
  7064. --
  7065. Jaap Vermeulen                    +--------------------------+
  7066.                         | Sequent Computer Systems |
  7067.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  7068.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  7069. 
  7070. 
  7071. Received: from uunet.ca by charon.cwi.nl with SMTP
  7072.     id AA16737 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 17:47:43 +0200
  7073. Received: from sni.ca ([192.75.236.203]) by mail.uunet.ca with SMTP id <9644(1)>; Wed, 12 May 1993 11:47:35 -0400
  7074. Received: from radium.sni.ca 
  7075.     by sni.ca (5.61/smail2.5/07-11-92)
  7076.     id AA03971; Wed, 12 May 93 11:53:31 -0400
  7077. Received: by radium.sni.CA (5.61/smail2.5/02-09-92)
  7078.     id AA11382; Wed, 12 May 93 11:53:27 -0400
  7079. Date:     Wed, 12 May 1993 11:53:27 -0400
  7080. From: tracy@radium.uucp (Tracy Tims)
  7081. Message-Id: <9305121553.AA11382@radium.sni.CA>
  7082. To: Guido.van.Rossum@cwi.nl
  7083. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Wed, 12 May 1993 06:48:23 -0400 <9305121048.AA04360=guido@voorn.cwi.nl>
  7084. Subject: continuation lines
  7085.  
  7086. I like the second version best, where newlines don't terminate lines
  7087. where the syntax doesn't allow it.
  7088.  
  7089. However, there is no reason why you can't make the changes in two
  7090. stages.  If you don't have time to rewrite the parser, just add the
  7091. parenthesis-balancing mod for now.  Add the rest when you have time.
  7092. The changes don't break old code.
  7093.  
  7094. I seem to write a number of tables here and there in my code, and the
  7095. biggest drawback to maintaining them is continuations, so even the
  7096. parenthesis-balancing is a big win.
  7097.  
  7098. Tracy Tims
  7099.  
  7100. PS.  I'm still working on the whole symbolic regular expression thing,
  7101. but I've just resigned from my current job.  I should have a bit more
  7102. time in my new job, but I'll be off the net for awhile.  I should be
  7103. able to make some progress, but it will be harder to tell people about
  7104. it.
  7105.  
  7106. 
  7107. 
  7108. Received: from optima.CS.Arizona.EDU by charon.cwi.nl with SMTP
  7109.     id AA17401 (5.65b/3.8/CWI-Amsterdam); Wed, 12 May 1993 18:19:31 +0200
  7110. Received: from chuckwalla.CS.Arizona.EDU by optima.CS.Arizona.EDU (5.65c/15) via SMTP
  7111.     id AA24791; Wed, 12 May 1993 09:19:12 MST
  7112. Date: Wed, 12 May 1993 09:19:10 MST
  7113. From: "Clint Jeffery" <cjeffery@cs.arizona.edu>
  7114. Message-Id: <199305121619.AA18230@chuckwalla.cs.arizona.edu>
  7115. Received: by chuckwalla.cs.arizona.edu; Wed, 12 May 1993 09:19:10 MST
  7116. To: jaap@sequent.com, Guido.van.Rossum@cwi.nl
  7117. In-Reply-To: Jaap Vermeulen's message of Wed, 12 May 1993 08:52:38 -0700 <9305121552.AA04404@eng2.sequent.com>
  7118. Subject: Oops, super() can't work!
  7119.  
  7120. Well, languages that have "class variables" can define a class variable
  7121. that knows the class of the method that is executing, and implement
  7122. "super" functionality on top of that.
  7123.  
  7124. But personally I agree with Guido's sentiments about the whole thing.
  7125. If you don't know which method you are going to get using super, aren't
  7126. you liable to get the wrong one?
  7127. 
  7128. 
  7129. Replied: Fri, 14 May 1993 11:22:22 +0200
  7130. Replied: "Tim Peters <tim@ksr.com> "
  7131. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  7132.     id AA17722 (5.65b/3.8/CWI-Amsterdam); Thu, 13 May 1993 22:33:28 +0200
  7133. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  7134.     id AA00718; Thu, 13 May 1993 16:33:06 -0400
  7135. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  7136.     id AA16262; Thu, 13 May 93 16:34:03 EDT
  7137. Received: by kaos.ksr.com (4.1/KSR-2.0)
  7138.     id AA14835; Thu, 13 May 93 16:33:59 EDT
  7139. Message-Id: <9305132033.AA14835@kaos.ksr.com>
  7140. To: python-list@cwi.nl
  7141. Subject: Re: continuation lines
  7142. Date: Thu, 13 May 93 16:33:58 -0400
  7143. From: Tim Peters <tim@ksr.com>
  7144.  
  7145. I think it's a neat idea.  Especially this part:
  7146.  
  7147. > ... or initialize lists as follows:
  7148. >
  7149. >     months = ['Jan', 'Feb', 'Mar',    # first Q
  7150. >           'Apr', 'May', 'Jun',    # second Q
  7151. >           'Jul', 'Aug', 'Sep',    # third Q
  7152. >           'Oct', 'Nov', 'Dec']    # fourth Q
  7153. >
  7154. > (Code using backslashes still works, but note that a line can't have a
  7155. > backslash *and* a comment, so there's a definite improvement here.)
  7156.  
  7157. I see I've accumulated a lot of initializers like
  7158.  
  7159. ix = [ 0x418, 0x280, 0x778, 0x58f, 0x3f1, \
  7160.        0x0c0, 0x241, 0x7c1, 0x60f, 0x613, \
  7161.        0x67f, 0x4f7, 0x2cd, 0x425, 0x4d3, \
  7162.        0x75a, 0x6d8, 0x601, 0x320, 0x1a9, ]
  7163.  
  7164. and I bet an embedded comment or two wouldn't have hurt them <snort>.
  7165.  
  7166. One downside:  it would take a major rewrite of python-mode.el to deal
  7167. with this correctly.  E.g., now a line is a continuation line if & only
  7168. if it's not the first line in the file, and the preceding line ends with
  7169. a backslash that's not part of a comment.  A simple-enough regexp can
  7170. deal with that reliably, & Python mode takes full advantage of that.
  7171.  
  7172. When the definition changes to require consideration of bracket nesting
  7173. depth too, regexps no longer suffice, and the alternatives are very messy
  7174. and/or slow (e.g., look up the docs for parse-partial-sexp, then realize
  7175. they explained it as clearly as they could given the function's inherent
  7176. complexity <0.9 grin>).
  7177.  
  7178. Without such changes, Python mode will treat the new-style continuation
  7179. lines as if they were not continuation lines, and that has some
  7180. irritating aspects.
  7181.  
  7182. too-hard-to-fix-in-the-time-i-can-make-so-i'll-call-it-a-feature<smile>-
  7183.    ly y'rs  - tim, who likes the idea very much anyway
  7184. 
  7185. 
  7186. Replied: Fri, 14 May 1993 10:06:37 +0200
  7187. Replied: "Lance Ellinghouse <lance@markv.com> python-list"
  7188. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  7189.     id AA22949 (5.65b/3.8/CWI-Amsterdam); Fri, 14 May 1993 00:28:22 +0200
  7190. From: Lance Ellinghouse <lance@markv.com>
  7191. X-Mailer: SCO System V Mail (version 3.2)
  7192. To: Guido.van.Rossum@cwi.nl
  7193. Subject: Re: continuation lines
  7194. Cc: python-list@cwi.nl
  7195. Date: Thu, 13 May 93 15:23:56 PDT
  7196. Message-Id:  <9305131524.aa02090@hermix.markv.com>
  7197.  
  7198. > I feel that this mod would be a useful addition to Python (also it
  7199. > fits nicely in the tradition of carefully trading certain principles
  7200. > for implementability).
  7201. > What do you think?
  7202.  
  7203. I would very much like to see this mod posted somewhere as this would
  7204. make some lists that I am building up (100+ elements) much easier to 
  7205. code! I also think it fits very nicely with other languages...
  7206.  
  7207. The current behavior is one that I did not like in Tcl (Tool Command Language)
  7208. and one reason why I moved to PYTHON (besides PYTHON's types and ability
  7209. to have custom types beyond just strings, and the module ideas in PYTHON,
  7210. and a bunch of other things like speed of PYTHON :) )...
  7211.  
  7212. Lance Ellinghouse
  7213. lance@markv.com
  7214.  
  7215. 
  7216. 
  7217. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  7218.     id AA13644 (5.65b/3.8/CWI-Amsterdam); Fri, 14 May 1993 10:06:40 +0200
  7219. Received: by voorn.cwi.nl with SMTP
  7220.     id AA10842 (5.65b/3.8/CWI-Amsterdam); Fri, 14 May 1993 10:06:38 +0200
  7221. Message-Id: <9305140806.AA10842=guido@voorn.cwi.nl>
  7222. To: Lance Ellinghouse <lance@markv.com>
  7223. Cc: python-list@cwi.nl
  7224. Subject: Re: continuation lines 
  7225. In-Reply-To: Your message of "Thu, 13 May 1993 15:23:56 MDT."
  7226.              <9305131524.aa02090@hermix.markv.com> 
  7227. From: Guido.van.Rossum@cwi.nl
  7228. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  7229. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  7230. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7231. Date: Fri, 14 May 1993 10:06:38 +0200
  7232. Sender: Guido.van.Rossum@cwi.nl
  7233.  
  7234. > I would very much like to see this mod posted somewhere as this would
  7235. > make some lists that I am building up (100+ elements) much easier to 
  7236. > code! I also think it fits very nicely with other languages...
  7237.  
  7238. Unfortunately the author of the mod found it necessary to reformat the
  7239. file before making the changes :-(.  I have retrofitted it in my
  7240. current source but that also contains another fix, so I can't
  7241. guarantee that the following diff will work with a clean 0.9.8 source.
  7242. Below is the diff for tokenizer.c; you also need to add "int level;"
  7243. to the end of the struct defined in tokenizer.h.
  7244.  
  7245. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7246.  
  7247. *** 2.12    1993/05/12 08:24:17
  7248. --- tokenizer.c    1993/05/12 11:35:42
  7249. ***************
  7250. *** 111,112 ****
  7251. --- 111,113 ----
  7252.       tok->lineno = 0;
  7253. +     tok->level = 0;
  7254.       return tok;
  7255. ***************
  7256. *** 392,394 ****
  7257.           }
  7258. !         if (!blankline) {
  7259.               if (col == tok->indstack[tok->indent]) {
  7260. --- 393,395 ----
  7261.           }
  7262. !         if (!blankline && tok->level == 0) {
  7263.               if (col == tok->indstack[tok->indent]) {
  7264. ***************
  7265. *** 485,487 ****
  7266.           tok->atbol = 1;
  7267. !         if (blankline)
  7268.               goto nextline;
  7269. --- 486,488 ----
  7270.           tok->atbol = 1;
  7271. !         if (blankline || tok->level > 0)
  7272.               goto nextline;
  7273. ***************
  7274. *** 612,613 ****
  7275. --- 613,628 ----
  7276.           tok_backup(tok, c2);
  7277. +     }
  7278. +     
  7279. +     /* Keep track of parenteses nesting level */
  7280. +     switch (c) {
  7281. +     case '(':
  7282. +     case '[':
  7283. +     case '{':
  7284. +         tok->level++;
  7285. +         break;
  7286. +     case ')':
  7287. +     case ']':
  7288. +     case '}':
  7289. +         tok->level--;
  7290. +         break;
  7291.       }
  7292. 
  7293. 
  7294. To: python-list
  7295. Subject: __init__
  7296. From: Guido.van.Rossum@cwi.nl
  7297. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  7298. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7299. Date: Tue, 18 May 1993 00:37:00 +0200
  7300. Sender: guido
  7301.  
  7302. The next Python release will have a feature that makes initialization
  7303. of class instances a little easier.  If a class defines a method named
  7304. __init__ then this method will be called when an instance of that
  7305. class is created.  If you pass any arguments to the class these will
  7306. be passed on to the __init__ method.  For example:
  7307.  
  7308.     class Window:
  7309.         def __init__(self, name):
  7310.             self.name = name
  7311.             "other initializations"
  7312.         "other methods"
  7313.  
  7314.     x = Window('testWindow')
  7315.  
  7316. Now think of derived classes.  If the derived class also calls a
  7317. method named __init__, it will be called.  But shouldn't the base
  7318. class's __init__ be called first?  Any C++ programmer would recognize
  7319. that __init__ is really a "constructor", and in C++ constructors of
  7320. base classes are guaranteed to be called before the derived class
  7321. constructor is called.
  7322.  
  7323. In old Python, where instead of __init__ there is a convention to have
  7324. a method init which is explicitly called by the caller at construction
  7325. time (e.g. x = Window().init('testWindow')) it is the responsibility
  7326. of the derived init method to also call the base class init method
  7327. (and so on recursively).
  7328.  
  7329. First I thought I could improve the situation, by walking the
  7330. inheritance tree at creation time ald call all __init__ methods that I
  7331. found, in a bottom-up order.  But then I realized that I had the same
  7332. problem as C++: how to pass each __init__ method its rightful
  7333. arguments?  In C++ this is solved with special syntax that is only
  7334. required if the base constructors need any arguments, but that's
  7335. beyond the capabilities of the Python interpreter because it's
  7336. impossible to tell how many arguments a function without actually
  7337. calling it.
  7338.  
  7339. There are several ways out.
  7340.  
  7341. One, only call the derived class' __init__ method and hope that it
  7342. will call the base class' __init__ method(s).  Pro: simple to
  7343. imeplement.  Con: no real guarantee that a base class' __init__ is
  7344. called.
  7345.  
  7346. Two, pass the same arguments to all __init__ methods.  Pro: still
  7347. easy to implement, plus guarantees call to base class' __init__ is
  7348. called.  Con: sometimes the derived class needs extra arguments, but
  7349. adding them to its __init__ method will break the derived class'
  7350. __init__ method, so kludges would be necessary.
  7351.  
  7352. I presonally think solution One isn't so bad, especially since one can
  7353. expect a little extra care from a (derived) class implementer.  (And
  7354. Python's type checking isn't really strong enough to prevent major
  7355. screw-ups anyway.)  I also think the problem of solution Two is a real
  7356. problem and I don't really see how to solve it.
  7357.  
  7358. Anybody have a different opinion or a clever idea?  Please speak up!
  7359.  
  7360. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7361. 
  7362. 
  7363. Received: from optima.CS.Arizona.EDU by charon.cwi.nl with SMTP
  7364.     id AA00825 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 00:59:00 +0200
  7365. Received: from chuckwalla.CS.Arizona.EDU by optima.cs.arizona.edu (5.65c/15) via SMTP
  7366.     id AA29473; Mon, 17 May 1993 15:58:57 MST
  7367. Date: Mon, 17 May 1993 15:58:56 MST
  7368. From: "Clint Jeffery" <cjeffery@cs.arizona.edu>
  7369. Message-Id: <199305172258.AA23439@chuckwalla.cs.arizona.edu>
  7370. Received: by chuckwalla.cs.arizona.edu; Mon, 17 May 1993 15:58:56 MST
  7371. To: Guido.van.Rossum@cwi.nl
  7372. Cc: python-list@cwi.nl
  7373. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Tue, 18 May 1993 00:37:00 +0200 <9305172237.AA01454=guido@voorn.cwi.nl>
  7374. Subject: __init__
  7375.  
  7376. This business about __init__'s in derived classes calling __init__'s
  7377. in superclasses is bumping up against a fairly general problem
  7378. (method combination).
  7379.  
  7380. The problem is more than just passing everyone the right arguments,
  7381. it is also the case that some hiearchies want to do it bottom-up
  7382. while other perfectly reasonable hierarchies want to do it top-down.
  7383.  
  7384. I wouldn't look to C++ as a role model for this!  Check out Flavors
  7385. (an OO Lisp dialect) or other dynamic OO languages for better approaches.
  7386.  
  7387. Clint Jeffery
  7388. cjeffery@cs.arizona.edu
  7389. 
  7390. 
  7391. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  7392.     id AA13655 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 02:31:19 +0200
  7393. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  7394.     id AA13152; Mon, 17 May 93 17:31:14 -0700
  7395. Received: by eng2.sequent.com (5.65/1.34)
  7396.     id AA17171; Mon, 17 May 93 17:31:13 -0700
  7397. Message-Id: <9305180031.AA17171@eng2.sequent.com>
  7398. To: Guido.van.Rossum@cwi.nl
  7399. Cc: python-list@cwi.nl
  7400. Subject: Re: __init__
  7401. Priority: Normal
  7402. Precedence: first-class
  7403. Organization: Sequent Computer Systems, Inc.
  7404.           Service Technology - MailStop: WIL2-610
  7405.           15450 S.W. Koll Parkway
  7406.           Beaverton, OR  97006-6063
  7407. X-Phone: (503) 578-4404
  7408. X-Fax: (503) 578-4540
  7409. X-Uucp: ...!uunet!sequent!jaap
  7410. X-Internet: jaap@sequent.com
  7411. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  7412.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  7413.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  7414. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Tue, 18 May 1993 00:37:00 +0200.
  7415.              <9305172237.AA01454=guido@voorn.cwi.nl> 
  7416. Date: Mon, 17 May 1993 17:31:12 -0700
  7417. From: Jaap Vermeulen <jaap@sequent.com>
  7418.  
  7419.  
  7420. | Anybody have a different opinion or a clever idea?  Please speak up!
  7421.  
  7422. No clever idea's (I never had :-), but certainly an opinion!  Looks
  7423. like option 2 is asking for trouble, so I recommend option 1).  What is
  7424. the reason behind this change?  Just to be able to call
  7425. class_name(arguments) and getting an instance, or are there other
  7426. reasons as well?
  7427.  
  7428. On another note:  How are the __len__ and other special functoins
  7429. implemented?  Is there considarable overhead for using these function
  7430. instead of the built-in ones, or should there be almost no difference?
  7431. Just curious...
  7432.  
  7433. Thanks,
  7434.  
  7435.     -Jaap-
  7436. --
  7437. Jaap Vermeulen                    +--------------------------+
  7438.                         | Sequent Computer Systems |
  7439.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  7440.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  7441. 
  7442. 
  7443. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  7444.     id AA24143 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 10:07:33 +0200
  7445. Received: by schelvis.cwi.nl with SMTP
  7446.     id AA08705 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 10:07:31 +0200
  7447. Message-Id: <9305180807.AA08705=jack@schelvis.cwi.nl>
  7448. To: Guido.van.Rossum@cwi.nl
  7449. Cc: python-list@cwi.nl
  7450. Subject: Re: __init__ 
  7451. In-Reply-To: Message by Guido.van.Rossum@cwi.nl ,
  7452.          Tue, 18 May 1993 00:37:00 +0200 , <9305172237.AA01454=guido@voorn.cwi.nl> 
  7453. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  7454. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  7455. X-Last-Band-Seen: Down by Law (29-4, Melkweg)
  7456. X-Mini-Review: pretty boring.
  7457. Date: Tue, 18 May 1993 10:07:30 +0200
  7458. From: Jack Jansen <Jack.Jansen@cwi.nl>
  7459.  
  7460. How about a little bit of extra syntax that allows the programmer to
  7461. declare whether python should call the base class __init__()'s
  7462. directly or not? So, something like:
  7463.  
  7464. class Base():
  7465.     def __init__(self, arg):
  7466.         ...
  7467.         return self
  7468.  
  7469. class Der_one(Base):
  7470.     def __init__(self, arg):    # Base.__init__ called automatically
  7471.         ...
  7472.         return self
  7473.  
  7474. class Der_two(*Base):
  7475.     def __init__(self, arg1, arg2):
  7476.         self = Base.__init__(self,arg1)    # Not called automatically
  7477.         ...
  7478.         return self
  7479. --
  7480. Jack Jansen        | If I can't dance I don't want to be part of
  7481. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  7482. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  7483. 
  7484. 
  7485. Received: from lebe.iaci.kun.nl by charon.cwi.nl with SMTP
  7486.     id AA20905 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 08:04:44 +0200
  7487. Received: by lebe.local (5.57/Ultrix3.0-C)
  7488.     id AA10333; Tue, 18 May 93 08:04:07 +0200
  7489. Message-Id: <9305180604.AA10333@lebe.local>
  7490. To: Guido.van.Rossum@cwi.nl
  7491. Cc: python-list@cwi.nl
  7492. From: hegt@lebe.iaci.kun.nl
  7493. Subject: Re: __init__
  7494. In-Reply-To: Your message of "Tue, 18 May 93 00:37:00 METDST."
  7495.              <9305172237.AA01454=guido@voorn.cwi.nl>
  7496. Date: Tue, 18 May 93 08:04:05 CDT
  7497. Sender: hegt@lebe.local
  7498.  
  7499.  
  7500. In message <9305172237.AA01454=guido@voorn.cwi.nl> you write:
  7501. >The next Python release will have a feature that makes initialization
  7502. >of class instances a little easier.  If a class defines a method named
  7503. >__init__ then this method will be called when an instance of that
  7504. >class is created.  If you pass any arguments to the class these will
  7505. >be passed on to the __init__ method.  For example:
  7506. >
  7507. ....
  7508. >
  7509. >Anybody have a different opinion or a clever idea?  Please speak up!
  7510. >
  7511. >--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7512.  
  7513. How about using the type of main(argc,argv) solution, i.e. provide
  7514. every __init__ method with a list containing the real arguments, from
  7515. which it can take what it understands?
  7516.  
  7517. I have no idea about the implementation aspects of such a solution, it
  7518. is just a thought ...
  7519.  
  7520. Rob Hegt
  7521. 
  7522. 
  7523. Replied: Tue, 18 May 1993 16:32:23 +0200
  7524. Replied: "Chris Hoffmann <choffman@vicorp.com> python-list"
  7525. Received: from relay1.UU.NET by charon.cwi.nl with SMTP
  7526.     id AA03138 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 15:56:15 +0200
  7527. Received: from vicorp.com (via vicorp.vicorp.com) by relay1.UU.NET with SMTP 
  7528.     (5.61/UUNET-internet-primary) id AA01677; Tue, 18 May 93 09:56:13 -0400
  7529. Received: from ithaca.vicorp.com by vicorp.com (4.1/SMI-4.1)
  7530.     id AA20902; Tue, 18 May 93 09:56:08 EDT
  7531. Date: Tue, 18 May 93 09:56:07 EDT
  7532. From: Chris Hoffmann <choffman@vicorp.com>
  7533. Message-Id: <9305181356.AA20902@vicorp.com>
  7534. To: python-list@cwi.nl
  7535. Subject: __init__
  7536.  
  7537.  
  7538. I prefer option (1), have the derived class explicitly call the
  7539. initializers for the base classes. 
  7540.  
  7541. I don't like the main(argc,argv) suggestion of Rob Hegt as the
  7542. arguments for the base class initializers may not even be in the
  7543. arguments for the derived class--the derived class may want to
  7544. synthesize them from the arguments it receives.
  7545.  
  7546. Personally, I think the idea that the derived class must explicitly
  7547. initialize the base class(es) and there are no implicit
  7548. initializations is perfectly acceptable. It's simple to explain and
  7549. the code is easier to understand (at least for me) as there are no
  7550. "hidden" function calls.
  7551.  
  7552. In other words, if you're going to have to allow explicit base class
  7553. initializations anyway, and I think you do, make them always required.
  7554. I'd like python to stay as lean as possible, so I'd rather not clutter
  7555. the language by having to support implicit initializations.  (There
  7556. are plenty of more useful things we can choose from when it comes time
  7557. to clutter!)
  7558.  
  7559.  
  7560. By the way, will there be a __del__(self) method that is called at
  7561. destruction time? My thought on this was that when python sees that an
  7562. object should be garbage collected, it calls the object's __del__
  7563. method (if any) before actually destroying it. Of course the
  7564. interpreter would have to check the object's refcount after calling
  7565. the function, as the method may have caused the object to be
  7566. referenced by some other object.
  7567.  
  7568. I don't really have a good example of why you'd want this, other than
  7569. for creating classes that keep track of how many instances of the
  7570. class exist. Perhaps someone else can think of a good reason for
  7571. having it. It just seems that if you have a function that is called at
  7572. object creation that you should have one that is called at object
  7573. destruction as well.
  7574.  
  7575.  
  7576. Chris
  7577.  
  7578. -----------------------------------------------------------------------------
  7579. Chris Hoffmann                VI Corporation
  7580. choffman@vicorp.com            47 Pleasant St. Northampton MA 01060
  7581. 
  7582. 
  7583. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  7584.     id AA04182 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 16:32:25 +0200
  7585. Received: by voorn.cwi.nl with SMTP
  7586.     id AA04906 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 16:32:24 +0200
  7587. Message-Id: <9305181432.AA04906=guido@voorn.cwi.nl>
  7588. To: Chris Hoffmann <choffman@vicorp.com>
  7589. Cc: python-list@cwi.nl
  7590. Subject: Re: __init__ and __del__
  7591. In-Reply-To: Your message of "Tue, 18 May 1993 09:56:07 MDT."
  7592.              <9305181356.AA20902@vicorp.com> 
  7593. From: Guido.van.Rossum@cwi.nl
  7594. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  7595. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  7596. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7597. Date: Tue, 18 May 1993 16:32:23 +0200
  7598. Sender: Guido.van.Rossum@cwi.nl
  7599.  
  7600. >From the responses so far I can conclude that having __init__
  7601. explicitly call the base class's __init__ is the best possible
  7602. solution, so let's move on to Chris' suggestion:
  7603.  
  7604. > By the way, will there be a __del__(self) method that is called at
  7605. > destruction time? My thought on this was that when python sees that an
  7606. > object should be garbage collected, it calls the object's __del__
  7607. > method (if any) before actually destroying it. Of course the
  7608. > interpreter would have to check the object's refcount after calling
  7609. > the function, as the method may have caused the object to be
  7610. > referenced by some other object.
  7611.  
  7612. The problem with this is, what to do if the __del__ call creates
  7613. another reference to the object?  You can't delete it then since the
  7614. new reference would be dangling.  But not deleting the object means
  7615. that the __del__ method may be called again later when the reference
  7616. count goes down to zero once again.  Would this be a problem?
  7617.  
  7618. > I don't really have a good example of why you'd want this, other than
  7619. > for creating classes that keep track of how many instances of the
  7620. > class exist. Perhaps someone else can think of a good reason for
  7621. > having it. It just seems that if you have a function that is called at
  7622. > object creation that you should have one that is called at object
  7623. > destruction as well.
  7624.  
  7625. Actually, there are lots of situations where a class is used as a
  7626. wrapper around some "real-world" object (e.g. a window or a temporary
  7627. file or an audio device) that you would want to destroy (or restore to
  7628. a previous state) when the instance goes away.  So yes, I think there
  7629. are many cases where this would be useful.
  7630.  
  7631. There's one problem with __del__, however: what if it raises an
  7632. exception?  __del__ will be called implicitly from a DECREF(x)
  7633. statement in the C code, and I'm not going to add error checking to
  7634. all DECREF() statements.  So these exceptions will have to be ignored.
  7635. In fact, there may already be an exception pending when DECREF() is
  7636. called, so it may have to save and restore the original exception.
  7637. Nasty!
  7638.  
  7639. One final thing to ponder: if we have a __del__ method, should the
  7640. interpreter guarantee that it is called when the program exits?  (Like
  7641. C++, which guarantees that destructors of global variables are
  7642. called.)  The only way to guarantee this is to go running around all
  7643. modules and delete all their variables.  But this means that __del__
  7644. method cannot trust that any global variables it might want to use
  7645. still exist, since there is no way to know in what order variables are
  7646. to be deleted.  Or is this not a useful feature?
  7647.  
  7648. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7649. 
  7650. 
  7651. To: Chris Hoffmann <choffman@vicorp.com>
  7652. cc: python-list
  7653. Subject: Re: __init__ and __del__
  7654. In-reply-to: Your message of "Tue, 18 May 1993 09:56:07 MDT."
  7655.              <9305181356.AA20902@vicorp.com> 
  7656. From: Guido.van.Rossum@cwi.nl
  7657. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  7658. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  7659. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7660. Date: Tue, 18 May 1993 16:32:23 +0200
  7661. Sender: guido
  7662.  
  7663. From the responses so far I can conclude that having __init__
  7664. explicitly call the base class's __init__ is the best possible
  7665. solution, so let's move on to Chris' suggestion:
  7666.  
  7667. > By the way, will there be a __del__(self) method that is called at
  7668. > destruction time? My thought on this was that when python sees that an
  7669. > object should be garbage collected, it calls the object's __del__
  7670. > method (if any) before actually destroying it. Of course the
  7671. > interpreter would have to check the object's refcount after calling
  7672. > the function, as the method may have caused the object to be
  7673. > referenced by some other object.
  7674.  
  7675. The problem with this is, what to do if the __del__ call creates
  7676. another reference to the object?  You can't delete it then since the
  7677. new reference would be dangling.  But not deleting the object means
  7678. that the __del__ method may be called again later when the reference
  7679. count goes down to zero once again.  Would this be a problem?
  7680.  
  7681. > I don't really have a good example of why you'd want this, other than
  7682. > for creating classes that keep track of how many instances of the
  7683. > class exist. Perhaps someone else can think of a good reason for
  7684. > having it. It just seems that if you have a function that is called at
  7685. > object creation that you should have one that is called at object
  7686. > destruction as well.
  7687.  
  7688. Actually, there are lots of situations where a class is used as a
  7689. wrapper around some "real-world" object (e.g. a window or a temporary
  7690. file or an audio device) that you would want to destroy (or restore to
  7691. a previous state) when the instance goes away.  So yes, I think there
  7692. are many cases where this would be useful.
  7693.  
  7694. There's one problem with __del__, however: what if it raises an
  7695. exception?  __del__ will be called implicitly from a DECREF(x)
  7696. statement in the C code, and I'm not going to add error checking to
  7697. all DECREF() statements.  So these exceptions will have to be ignored.
  7698. In fact, there may already be an exception pending when DECREF() is
  7699. called, so it may have to save and restore the original exception.
  7700. Nasty!
  7701.  
  7702. One final thing to ponder: if we have a __del__ method, should the
  7703. interpreter guarantee that it is called when the program exits?  (Like
  7704. C++, which guarantees that destructors of global variables are
  7705. called.)  The only way to guarantee this is to go running around all
  7706. modules and delete all their variables.  But this means that __del__
  7707. method cannot trust that any global variables it might want to use
  7708. still exist, since there is no way to know in what order variables are
  7709. to be deleted.  Or is this not a useful feature?
  7710.  
  7711. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7712. 
  7713. 
  7714. Replied: Tue, 18 May 1993 17:08:38 +0200
  7715. Replied: "dussud@lucid.com (Patrick Dussud) "
  7716. Received: from aspen.lucid.com by charon.cwi.nl with SMTP
  7717.     id AA05009 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 17:02:44 +0200
  7718. Received: by aspen.lucid.com (4.1/SMI-4.1)
  7719.     id AA18997; Tue, 18 May 93 08:02:38 PDT
  7720. Date: Tue, 18 May 93 08:02:38 PDT
  7721. From: dussud@lucid.com (Patrick Dussud)
  7722. Message-Id: <9305181502.AA18997@aspen.lucid.com>
  7723. To: Guido.van.Rossum@cwi.nl
  7724. Cc: python-list@cwi.nl
  7725. In-Reply-To: <9305172237.AA01454=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  7726. Subject: __init__
  7727.  
  7728.  
  7729. The Lisp community faced the same problem. Flavors and then CLOS adopted
  7730. solution 1 with the convention that initialization values should be keyword
  7731. arguments. They have the form <key> <value>. The original list is passed to
  7732. all of the methods, which are free to pick the arguments they care about. I
  7733. don't see how 1 can work without keyword argument, so I guess that 2 would be
  7734. better in the context of Python.
  7735. Patrick.
  7736. 
  7737. 
  7738. Received: from att-out.att.com by charon.cwi.nl with SMTP
  7739.     id AA05576 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 17:23:49 +0200
  7740. From: hzsbg01!jbuhrma@hvgtw.att.com
  7741. Received: from hzsbc03 by hzsbg01 (4.1/SMI-4.1)
  7742.     id AA19630; Tue, 18 May 93 17:06:32 +0200
  7743. Date: Tue, 18 May 93 17:06:32 +0200
  7744. Original-From: hzsbg01!jbuhrma
  7745. Message-Id: <9305181506.AA19630@hzsbg01>
  7746. To: choffman@vicorp.com
  7747. Subject: Re: __init__
  7748. Cc: python-list@cwi.nl
  7749.  
  7750. > By the way, will there be a __del__(self) method that is called at
  7751. > destruction time? [...]  I don't really have a good example of why
  7752. > you'd want this, other than for creating classes that keep track of
  7753. > how many instances of the class exist. Perhaps someone else can think
  7754. > of a good reason for having it.
  7755.  
  7756. Look at the draw object in the stdwin module.  When you delete the
  7757. object, things get actually painted on screen.  Up 'till now such a
  7758. scheme is only possible with builtin objects.
  7759.  
  7760. -- Jan-Hein Buhrman -- AT&T Huizen NL -- <jbuhrma%hzsbg01@hvlpa.att.com> --
  7761. ---------------------- +31 35 87.4278 --- ...!att!hvlpa!hzsbg01!jbuhrma ---
  7762. ``When everything is bad, it must be good to know the worst''
  7763. --Francis Bradley, quoted on ``Who's Afraid of?... The Art of Noise!''
  7764.  
  7765.  
  7766. 
  7767. 
  7768. To: dussud@lucid.com (Patrick Dussud)
  7769. Subject: Re: __init__ 
  7770. In-reply-to: Your message of "Tue, 18 May 1993 08:02:38 MDT."
  7771.              <9305181502.AA18997@aspen.lucid.com> 
  7772. From: Guido.van.Rossum@cwi.nl
  7773. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  7774. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  7775. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7776. Date: Tue, 18 May 1993 17:08:38 +0200
  7777. Sender: guido
  7778.  
  7779. > The Lisp community faced the same problem. Flavors and then CLOS adopted
  7780. > solution 1 with the convention that initialization values should be keyword
  7781. > arguments. They have the form <key> <value>. The original list is passed to
  7782. > all of the methods, which are free to pick the arguments they care about. I
  7783. > don't see how 1 can work without keyword argument, so I guess that 2 would be
  7784. > better in the context of Python.
  7785.  
  7786. Are you sure you haven't reversed the options?  My option 1 calls only
  7787. the derived class' __init__ and leaves it up to that method to call
  7788. the base class' __init__.  My option 2 calls all base* class __init__
  7789. methods (buttom up) with the same argument list.  This sounds like the
  7790. reverse of what you're describing...
  7791.  
  7792. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7793. 
  7794. 
  7795. Received: from aspen.lucid.com by charon.cwi.nl with SMTP
  7796.     id AA07128 (5.65b/3.8/CWI-Amsterdam); Tue, 18 May 1993 18:09:36 +0200
  7797. Received: by aspen.lucid.com (4.1/SMI-4.1)
  7798.     id AA19117; Tue, 18 May 93 09:09:33 PDT
  7799. Date: Tue, 18 May 93 09:09:33 PDT
  7800. From: dussud@lucid.com (Patrick Dussud)
  7801. Message-Id: <9305181609.AA19117@aspen.lucid.com>
  7802. To: Guido.van.Rossum@cwi.nl
  7803. In-Reply-To: <9305181508.AA05058=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  7804. Subject: __init__ 
  7805.  
  7806.  
  7807.    From: Guido.van.Rossum@cwi.nl
  7808.    X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  7809.    X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  7810.    X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7811.    Date: Tue, 18 May 1993 17:08:38 +0200
  7812.    Sender: Guido.van.Rossum@cwi.nl
  7813.  
  7814.    > The Lisp community faced the same problem. Flavors and then CLOS adopted
  7815.    > solution 1 with the convention that initialization values should be keyword
  7816.    > arguments. They have the form <key> <value>. The original list is passed to
  7817.    > all of the methods, which are free to pick the arguments they care about. I
  7818.    > don't see how 1 can work without keyword argument, so I guess that 2 would be
  7819.    > better in the context of Python.
  7820.  
  7821.    Are you sure you haven't reversed the options?  My option 1 calls only
  7822.    the derived class' __init__ and leaves it up to that method to call
  7823.    the base class' __init__.  My option 2 calls all base* class __init__
  7824.    methods (buttom up) with the same argument list.  This sounds like the
  7825.    reverse of what you're describing...
  7826.  
  7827.    --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7828.  
  7829. Right you are. 
  7830.  
  7831. Patrick.
  7832. 
  7833. 
  7834. Replied: Wed, 02 Jun 1993 13:19:53 +0200
  7835. Replied: "Doug Moen <dmoen@utcc.utoronto.ca> "
  7836. Received: from gpu.utcc.utoronto.ca by charon.cwi.nl with SMTP
  7837.     id AA23130 (5.65b/3.8/CWI-Amsterdam); Fri, 28 May 1993 17:24:58 +0200
  7838. Received: by gpu.utcc.utoronto.ca id <18697>; Fri, 28 May 1993 11:24:41 -0400
  7839. From: Doug Moen <dmoen@utcc.utoronto.ca>
  7840. To: python-list@cwi.nl
  7841. Subject: replacing stdwin
  7842. Message-Id: <93May28.112441edt.18697@gpu.utcc.utoronto.ca>
  7843. Date:     Fri, 28 May 1993 11:24:33 -0400
  7844.  
  7845. I am new to python, and new to python-list, so excuse me if this has been
  7846. discussed before.  
  7847.  
  7848. I have been looking around for an industrial strength scripting and extension
  7849. language to incorporate into a new product my company is developing, and I've
  7850. pretty much settled on Python.  The other thing we need is an industrial
  7851. strength portable window system interface, with both C/C++ and Python bindings.
  7852. Sadly, stdwin just doesn't cut it.  So, I'm looking for alternatives.
  7853.  
  7854. One possibility is to purchase a commercial platform-independent GUI library
  7855. such as Aspect, C++/Views, Galaxy, Zinc, etc, and create a Python interface.
  7856. Has anybody done this?
  7857.  
  7858. Another possibility is to find a non-commercial GUI library (hopefully, one
  7859. that is distributed on the same terms as Python), and create a Python interface
  7860. to that.  The advantage of this second approach is that the resulting package
  7861. could be made freely distributable, and incorporated into the Python
  7862. distribution.  Any leads on this?
  7863.  
  7864. Are there any "official" plans to replace stdwin with something better?
  7865.  
  7866. P.S.
  7867. Because we are developing a commercial product, we are committing significant
  7868. manpower to fixing bugs, porting to new platforms*, creating a regression
  7869. test suite, and adding enhancements.  I would ideally like to fold these
  7870. changes into the main Python distribution, so that we can benefit from the
  7871. work that other Python developers are doing.  By the way, just how much
  7872. Python development activity is going on right now, and by how many people?
  7873. When will version 1.0 be released?
  7874.  
  7875. *New platforms:  We are planning a 32 bit Microsoft Windows port,
  7876. with dynamic loading implemented using DLLs.  Probably this will force us
  7877. to put the Python interpreter into a DLL.  Has anyone done this before?
  7878.  
  7879. Doug Moen    dmoen@utcc.utoronto.ca
  7880. 
  7881. 
  7882. To: Doug Moen <dmoen@utcc.utoronto.ca>
  7883. Subject: Re: replacing stdwin 
  7884. In-reply-to: Your message of "Fri, 28 May 1993 11:24:33 MDT."
  7885.              <93May28.112441edt.18697@gpu.utcc.utoronto.ca> 
  7886. From: Guido.van.Rossum@cwi.nl
  7887. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  7888. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  7889. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7890. Date: Wed, 02 Jun 1993 13:19:53 +0200
  7891. Sender: guido
  7892.  
  7893. Hi,
  7894.  
  7895. I suppose you are less than impressed with the response to your
  7896. mail...  So am I.  Here is what I know.
  7897.  
  7898. > One possibility is to purchase a commercial platform-independent GUI library
  7899. > such as Aspect, C++/Views, Galaxy, Zinc, etc, and create a Python interface.
  7900. > Has anybody done this?
  7901.  
  7902. Well, nobody has told me anybody about it if they did, so I very much
  7903. doubt it.  Have you thought of Interviews?  It's in C++, but Python
  7904. mixes reasonably well with that.  Or what about XVT (a commercial
  7905. stdwin-like package)?
  7906.  
  7907. > Another possibility is to find a non-commercial GUI library (hopefully, one
  7908. > that is distributed on the same terms as Python), and create a Python interface
  7909. > to that.  The advantage of this second approach is that the resulting package
  7910. > could be made freely distributable, and incorporated into the Python
  7911. > distribution.  Any leads on this?
  7912.  
  7913. Nothing, but a friend just pointed me to a public domain platform
  7914. independent programming environment called wxwin, available for xview
  7915. (OpenWindows), Motif and MS Windows.  The only pointer I have is that
  7916. someone found it at the University of Edinburgh...
  7917.  
  7918. > Are there any "official" plans to replace stdwin with something better?
  7919.  
  7920. The current trend in Python is towards Motif (see below), but that
  7921. leaves the Mac and PC users rather in the cold...
  7922.  
  7923. > Because we are developing a commercial product, we are committing significant
  7924. > manpower to fixing bugs, porting to new platforms*, creating a regression
  7925. > test suite, and adding enhancements.  I would ideally like to fold these
  7926. > changes into the main Python distribution, so that we can benefit from the
  7927. > work that other Python developers are doing.
  7928.  
  7929. Good idea!  If you do make changes to the distribution, please don't
  7930. reformat them -- context diffs relative to the latest release have the
  7931. highest chances of being folded back.
  7932.  
  7933. > By the way, just how much
  7934. > Python development activity is going on right now, and by how many people?
  7935.  
  7936. I know that several companies are considering Python as a scripting or
  7937. extension language for one of their UNIX-based products.  I don't know
  7938. if they'd all let me mention their names though -- they are reading
  7939. the list, so if they want to respond they can do so!  Here are a few
  7940. that I think are safe to mention:
  7941.  
  7942. Sunrise Software have a version of their Motif GUI builder "ezX" which
  7943. supports Python as one of the possible scripting languages.  They've
  7944. demonstrated this last year and I'm an official beta tester...
  7945.  
  7946. V.I. Corporation have also invested quite some time in Python already,
  7947. they are working on a very nice set of Motif bindings that they will
  7948. release under similar conditions as the rest of Python.  (While they
  7949. were working on this, I did my own set of Motif bindings, which has
  7950. somewhat less functionality but is much more robust so far.  I hope I
  7951. can prevent having two sets of incompatible bindings, so policy is to
  7952. release nothing until this is resolved...)
  7953.  
  7954. Several others are less far (or tell me less about what they are
  7955. doing).  There are also several companies who use Python for in-house
  7956. projects like automated testing.
  7957.  
  7958. Hope this helps...
  7959.  
  7960. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  7961.  
  7962. PS: I'm sure I've seen your name on the net before but can't remember
  7963. where or how.  Quite possibly we've even exchanged mail log ago.  You
  7964. must be the author of some kind of famous software.  Give me a
  7965. clue...?
  7966. 
  7967. 
  7968. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  7969.     id AA26844 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 01:08:41 +0200
  7970. Received: by voorn.cwi.nl with SMTP
  7971.     id AA06557 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 01:08:39 +0200
  7972. Message-Id: <9306032308.AA06557=guido@voorn.cwi.nl>
  7973. To: python-list@cwi.nl
  7974. Subject: DISCUSSION: Naming conventions (for C code)
  7975. From: Guido.van.Rossum@cwi.nl
  7976. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  7977. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  7978. Date: Fri, 04 Jun 1993 01:08:39 +0200
  7979. Sender: Guido.van.Rossum@cwi.nl
  7980.  
  7981. Naming Conventions -- A Draft Proposal
  7982. **************************************
  7983.  
  7984. It is quite easy to extend Python with a new module written in C.  It
  7985. should be equally easy to embed the Python interpreter as a library in
  7986. an existing (or new) application.  This is indeed possible, but there
  7987. is a potential problem when the application is large: the Python
  7988. interpreter library defines many external names that may clash with
  7989. names defined by the application.  To a lesser extend the macros,
  7990. structures and typedefs defined in Python's header files may also
  7991. clash with application-defined names (or with names defined by other
  7992. libraries, when the application needs to use several libraries in one
  7993. file).
  7994.  
  7995. This article proposes a change to the naming of all external
  7996. functions, macros, structures, typedefs etc. that are in any way
  7997. visible to the application with the intent to make clashes avoidable.
  7998. (This excludes the names of static functions and variables, local
  7999. variables, structure members, and macros, structures and typedefs
  8000. defined in .c files.)  At the same time the set of names is somewhat
  8001. rationalized to make it easier to guess where a name is defined.
  8002.  
  8003. The purpose of this proposal is to get feedback.  This is your chance
  8004. to make your voice heard!  Please evaluate every aspect of the
  8005. proposal and let me know whether you like it or not.  No effort has
  8006. yet begun to implement the proposal, so there are no big costs
  8007. involved in changes to the proposal.  Your opinion is especially
  8008. important if you have written (or are maintaining) code that extends
  8009. the Python interpreter, since you will have to change your code and
  8010. learn to use the new conventions.
  8011.  
  8012. Note that these changes affect the C code that implements the Python
  8013. interpreter (and its extensions) only; the Python language as seen by
  8014. Python programmers will remain unchanged!
  8015.  
  8016. Basic Conventions
  8017. =================
  8018.  
  8019. The mechanism to avoid clashes is to prefix all relevant names with
  8020. the string Py.  This gives an application a very simple way to avoid
  8021. clashes: simply don't define names starting with Py in the
  8022. application.  A similar mechanism is successfully used by most
  8023. widespread libraries, e.g. X.
  8024.  
  8025. The full naming scheme gives functions a name as follows:
  8026. Py<Module>_<Function>, where <Module> is the (sometimes abbreviated)
  8027. name of the module to which the function belongs (this may also be a
  8028. basic type), and <Function> is a descriptive name for the function.
  8029. The <Module> and <Function> parts use a mixed-case convention: each
  8030. is spelled with an initial capital letter, and if they consist of
  8031. multiple words each word has an initial capital.  Embedded underscores
  8032. are not used except between <Module> and <Function>.  Some examples:
  8033.  
  8034. PyList_Append
  8035. PyList_GetItem
  8036. PyList_New
  8037. PyString_GetValue
  8038. PyErr_SetStr
  8039.  
  8040. Functions applying to any kind of objects, and some other oft-used
  8041. utility functions, have a prefix of just Py_, e.g.
  8042.  
  8043. Py_Print
  8044. Py_Repr
  8045. Py_GetAttr
  8046. Py_GetArg
  8047. Py_MakeValue
  8048.  
  8049. Global variables are named using similar conventions, e.g.
  8050.  
  8051. PyType_List
  8052. Py_ZeroDivisionError
  8053.  
  8054. Functions and variables that have to be global for some reason but are
  8055. not part of the official interface have an initial underscore, e.g.
  8056.  
  8057. _Py_RefTotal
  8058.  
  8059. Macros with arguments are named like functions, e.g.:
  8060.  
  8061. Py_IsList
  8062. Py_IncRef
  8063.  
  8064. Macros without arguments (symbolic constants) have a second part that
  8065. is entirely in capitals and uses underscores to separate words.  So
  8066. do enums.  E.g.:
  8067.  
  8068. Py_PRINT_RAW
  8069.  
  8070. Typedefs contain no underscore; they consist of Py followed by one or
  8071. more words with initial capitals, e.g.:
  8072.  
  8073. PyObject
  8074. PyListObject
  8075.  
  8076. Most of these typedef names correspond to structures; the structure
  8077. tag will be the typedef name prefixed with an underdscore.
  8078.  
  8079. Note that the current system has a number of structures that are not
  8080. covered by typedefs.  These will be given typedef names.
  8081.  
  8082. Also note that pointer types will continue to be written with the "*"
  8083. notation, e.g. "PyObject *".  Pointers in C have sufficiently special
  8084. semantics to make it important in practice to know whether a
  8085. particular variable is a pointer; e.g. Python frequently uses casts
  8086. between various object pointers.
  8087.  
  8088. Header files will follow the conventions for typedef names, e.g.
  8089.  
  8090. "PyList.h"
  8091.  
  8092. A header named "Python.h" will collect almost all useful headers.
  8093.  
  8094. Transition Period
  8095. =================
  8096.  
  8097. During a transition period, which will last at least two releases that
  8098. each live at least 3 months (giving a total of at least 6 months), it
  8099. will be possible to use the old names and the new names together.
  8100. The transition mechanism uses #define to identify the new and old names.
  8101.  
  8102. In the first transition release, the (majority of) source code will
  8103. still use the old names, including the old header file names, but
  8104. macros will be defined to support the use of the new names, e.g.:
  8105.  
  8106. #define PyObject object
  8107.  
  8108. In the second transition release, the source code will use the new
  8109. names, also for header file names, and macros will be defined to
  8110. support code that still uses the old names, e.g.:
  8111.  
  8112. #define object PyObject
  8113.  
  8114. Headers with the alternative names will be provided in both cases.
  8115.  
  8116. In both transition releases, the compatibility macros will be gathered
  8117. in a single header file (a different one each time!).
  8118.  
  8119. A Python script will be provided which translates C code from the old
  8120. to the new naming conventions with 99% accuracy.  It remains to be
  8121. seen whether occurrences in comments should be replaced; when comments
  8122. refer to functions and typedefs etc., they should, but some names
  8123. (e.g. object!) can also be used as a noun, so global substitutions may
  8124. cause undesired effects.  Also, there are some situations where names
  8125. occurring in strings must be substituted!
  8126.  
  8127. Other Changes
  8128. =============
  8129.  
  8130. It may be possible to introduce other changes as well, e.g. changes to
  8131. the source tree: I might separate the .h files from the .c files,
  8132. separate optional modules from the required part of the interpreter,
  8133. move the parser generator to its own directory.  (Anything else?)
  8134.  
  8135. Alternative Proposals
  8136. =====================
  8137.  
  8138. A much simpler alternative would be to prefix all names with py_
  8139. (sometimes PY_) and leave everything else unchanged: py_object,
  8140. py_getattr, py_is_listobject, etc.  This will be easier for those
  8141. (like myself!) whose eyes and fingers have been trained to use the
  8142. current names, but it will leave the existing inconsistencies in
  8143. place.  (The Python language itself uses lowercase for must
  8144. situations, but its library is not too consistent, so it cannot really
  8145. serve as a guideline here.)
  8146.  
  8147. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  8148. 
  8149. 
  8150. Received: from petunia.cwi.nl by charon.cwi.nl with SMTP
  8151.     id AA05525 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 08:07:36 +0200
  8152. Received: by petunia.cwi.nl with SMTP
  8153.     id AA04902 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 08:07:35 +0200
  8154. Message-Id: <9306040607.AA04902=ivan@petunia.cwi.nl>
  8155. To: python-list@cwi.nl
  8156. Subject: Re: DISCUSSION: Naming conventions (for C code) 
  8157. In-Reply-To: Your message of "Fri, 04 Jun 1993 01:08:39 MDT."
  8158.              <9306032308.AA06557=guido@voorn.cwi.nl> 
  8159. Date: Fri, 04 Jun 1993 08:07:34 +0200
  8160. From: Ivan Herman <Ivan.Herman@cwi.nl>
  8161.  
  8162.  
  8163. I totally agree with the necessity of a consistent naming convention;
  8164. being in the process in embedding the interpreter into a C++ program, we
  8165. clearly feel the necessity. Your proposal seems to be o.k. to me; in
  8166. fact, I do not think a long discussion is necessary. So: go for it!
  8167.  
  8168. Ivan
  8169. 
  8170. 
  8171. Received: from gpu.utcc.utoronto.ca by charon.cwi.nl with SMTP
  8172.     id AA05753 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 08:16:47 +0200
  8173. Received: by gpu.utcc.utoronto.ca id <18711>; Fri, 4 Jun 1993 02:16:39 -0400
  8174. From: Doug Moen <dmoen@utcc.utoronto.ca>
  8175. To: python-list@cwi.nl
  8176. Subject: Re:  DISCUSSION: Naming conventions (for C code)
  8177. Message-Id: <93Jun4.021639edt.18711@gpu.utcc.utoronto.ca>
  8178. Date:     Fri, 4 Jun 1993 02:16:29 -0400
  8179.  
  8180. I approve of the proposed new consistent naming convention.
  8181.  
  8182. The programming convention we use suffixes all typedef names with "_t";
  8183. thus, struct PyObject { ... } PyObject_t.  The _t convention has the
  8184. advantage of being instantly understood by all C programmers (because of
  8185. size_t, etc, in the ANSI C standard).
  8186.  
  8187. I'm not so happy about the alternative suggestion of just prefixing the
  8188. existing names with py_, since this "will leave the existing inconsistencies
  8189. in place".  Python has a great future ahead of it; a little work at fixing
  8190. inconsistencies now will repay itself with interest.  Future generations
  8191. will praise your foresight (just as they curse the designers of C for not
  8192. fixing the gets/fgets botch in the mid seventies, to avoid inconveniencing
  8193. a few dozen people).
  8194.  
  8195. The directory reorganization (putting different kinds of files into different
  8196. directories) will be a big win for us, since it will make it much easier
  8197. for us to build python using the Qef construction tool (we don't use make).
  8198.  
  8199. When you rename the header files, please don't exceed 8 characters before
  8200. the ".h"; this will make it easier for me when I compile the DOS and Windows
  8201. versions of Python.
  8202.  
  8203. You mention a python script for automating the name change.
  8204. Here is how we do name changes of this sort at my organization.
  8205.  
  8206. 1. First, we use a grep variant which takes a list of C identifiers
  8207.    rather than a regular expression, and produce a file of the form
  8208.     filename:lineno:contents of file
  8209.     ...
  8210.    This is the same format that grep outputs.
  8211.  
  8212. 2. Then, we visually scan the file, looking for lines that shouldn't
  8213.    actually be changed (eg, comment lines containing the word "object"
  8214.    in the English sense); these lines are deleted.
  8215.  
  8216. 3. Then, we perform a global substitution on the file.  We use a tool
  8217.    which takes a dictionary of old-C-identifier, new-C-identifier pairs,
  8218.    one pair per line, separated by tabs.
  8219.  
  8220. 4. A final visual scan, to make sure no mistaken substitutions were made.
  8221.  
  8222. 5. Finally, we feed the file to a tool called "repl", which interprets
  8223.    the filename and lineno fields, and replaces the indicated lines in
  8224.    the indicated files with the new text.
  8225.  
  8226. With the above procedure, large scale name changes are fairly easy
  8227. to do.  The nice thing about this procedure is that it's quick and easy to
  8228. eyeball the changes before you commit to them.
  8229. 
  8230. 
  8231. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  8232.     id AA12564 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 10:54:14 +0200
  8233. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11582>; Fri, 4 Jun 1993 01:53:57 PDT
  8234. Received: by eros.EuroPARC.Xerox.COM with SMTP
  8235.     (5.65c/IDA-1.2.9) id AA19888; Fri, 4 Jun 1993 09:53:36 +0100
  8236. Message-Id: <199306040853.AA19888@eros.EuroPARC.Xerox.COM>
  8237. To: Guido.van.Rossum@cwi.nl
  8238. Subject: Re: DISCUSSION: Naming conventions (for C code) 
  8239. In-Reply-To: Your message of "Thu, 03 Jun 93 16:08:39 PDT."
  8240.              <9306032308.AA06557=guido@voorn.cwi.nl> 
  8241. Date:     Fri, 4 Jun 1993 01:53:35 PDT
  8242. From: Fraser@europarc.xerox.com
  8243.  
  8244.  
  8245. Guido -
  8246.  
  8247. The proposals seem very sensible to me. I have just a couple of
  8248. modules which would need adjusting, but that would be 10 minutes'
  8249. work.
  8250.  
  8251. I am planning to try embedding the interpreter in a Modula-3 program
  8252. in the near future (because it seems like a much happier marriage
  8253. than, say, M3 & Tcl) and this could be a great help.  I hope it's not
  8254. too much work for you, though!
  8255.  
  8256. Quentin
  8257.  
  8258. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  8259. Quentin Stafford-Fraser         
  8260. Rank Xerox EuroPARC,            Oh, what a tangled web we weave,
  8261. Cambridge, UK            When first we practise to deceive
  8262. Tel: +44 223 341529          But when we've practised quite a while
  8263. Fax: +44 223 341510          How vastly we improve our style!
  8264. Fraser@europarc.xerox.com
  8265.  
  8266. 
  8267. 
  8268. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  8269.     id AA16333 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 12:56:17 +0200
  8270. Received: by schelvis.cwi.nl with SMTP
  8271.     id AA07505 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 12:56:16 +0200
  8272. Message-Id: <9306041056.AA07505=jack@schelvis.cwi.nl>
  8273. To: python-list@cwi.nl
  8274. Subject: Re: DISCUSSION: Naming conventions (for C code) 
  8275. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  8276. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  8277. X-Last-Band-Seen: NO FX (Melkweg, 1-6)
  8278. X-Mini-Review: Great!
  8279. Date: Fri, 04 Jun 1993 12:56:15 +0200
  8280. From: Jack Jansen <Jack.Jansen@cwi.nl>
  8281.  
  8282. Sounds like a good idea.
  8283. --
  8284. Jack Jansen        | If I can't dance I don't want to be part of
  8285. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  8286. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  8287. 
  8288. 
  8289. Received: from inesc.inesc.pt by charon.cwi.nl with SMTP
  8290.     id AA18405 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 14:06:41 +0200
  8291. Received: from flausina.inesc.pt by inesc.inesc.pt with SMTP;
  8292.     id AA10707 (5.65c/SunOS4.1.3); Fri, 4 Jun 1993 14:05:27 +0200
  8293. Received: by flausina.inesc.pt (4.1/SunOS4.1.1)
  8294.     id AA14177; Fri, 4 Jun 93 14:06:51 +0200
  8295. Date: Fri, 4 Jun 93 14:06:51 +0200
  8296. From: pereira@flausina.inesc.pt (Jose Pereira)
  8297. Message-Id: <9306041206.AA14177@flausina.inesc.pt>
  8298. To: Guido.van.Rossum@cwi.nl
  8299. Cc: python-list@cwi.nl
  8300. Subject: DISCUSSION: Naming conventions (for C code)
  8301. In-Reply-To: <9306032308.AA06557=guido@voorn.cwi.nl>
  8302. References: <9306032308.AA06557=guido@voorn.cwi.nl>
  8303.  
  8304.  
  8305. It sounds a Good & Sensible Thing. I would only make a suggestion:
  8306.  
  8307. Instead of:
  8308. >    Global variables are named using similar conventions, e.g.
  8309. >
  8310. >    PyType_List
  8311. >    Py_ZeroDivisionError
  8312.  
  8313. I would say:
  8314.  
  8315.     PyType_list
  8316.     Py_zeroDivisionError
  8317.  
  8318. That is, to make a distinction between function names and variables by
  8319. starting these with a lower case letter.
  8320.  
  8321. It's not that important, but helps a little when you are using a
  8322. debugger and want a quick visual check of a particular global name.
  8323.  
  8324. --
  8325.  
  8326. ----------------------------------------------------------------------
  8327. Jose' Pereira
  8328.  
  8329.  
  8330.          INESC (Inst. Eng. Sistemas e Computadores)
  8331.              R. Alves Redol 9, 6. 1000 Lisboa, PORTUGAL.
  8332.              Phone.: +351 1 3100225 Fax...: +351 1 525843
  8333.     e-mail: jmp@inesc.pt  PSI...: %(0268)004010314::inesc::jmp
  8334.  
  8335. 
  8336. 
  8337. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  8338.     id AA24529 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 17:07:56 +0200
  8339. From: Lance Ellinghouse <lance@markv.com>
  8340. X-Mailer: SCO System V Mail (version 3.2)
  8341. To: Guido.van.Rossum@cwi.nl
  8342. Subject: Re: DISCUSSION: Naming conventions (for C code)
  8343. Cc: python-list@cwi.nl
  8344. Date: Fri, 4 Jun 93 8:06:50 PDT
  8345. Message-Id:  <9306040806.aa29166@hermix.markv.com>
  8346.  
  8347. >Global variables are named using similar conventions, e.g.
  8348. >
  8349. >PyType_List
  8350. >Py_ZeroDivisionError
  8351.  
  8352. I think that variables should have the first letter after the 
  8353. underscore in lowercase to distinguise them from functions...
  8354.  
  8355. >Typedefs contain no underscore; they consist of Py followed by one or
  8356. >more words with initial capitals, e.g.:
  8357. >
  8358. >PyObject
  8359. >PyListObject
  8360.  
  8361. I like having something like PyObject_t. This will make it easier to 
  8362. look into the code and see if it is a typedef. It is also more
  8363. standard since most of ANSI typedefs are like that..
  8364.  
  8365. >Also note that pointer types will continue to be written with the "*"
  8366. >notation, e.g. "PyObject *".  Pointers in C have sufficiently special
  8367. >semantics to make it important in practice to know whether a
  8368. >particular variable is a pointer; e.g. Python frequently uses casts
  8369. >between various object pointers.
  8370.  
  8371. I don't like this.. I like the following..
  8372.  
  8373. typedef struct _PyObject {
  8374.     ....
  8375.     } PyObject_t, *pPyObject_t, **ppPyObject_t;
  8376.  
  8377. Or
  8378.  
  8379. typedef struct _PyObject {
  8380.     ....
  8381.     } PyObject_t, *PyObjectP_t, **PyObjectPP_t;
  8382.  
  8383. This makes the code a little cleaner to read and makes it
  8384. harder to miss putting in a '*'.
  8385.  
  8386. >Other Changes
  8387. >=============
  8388. >
  8389. >It may be possible to introduce other changes as well, e.g. changes to
  8390. >the source tree: I might separate the .h files from the .c files,
  8391. >separate optional modules from the required part of the interpreter,
  8392. >move the parser generator to its own directory.  (Anything else?)
  8393.  
  8394. Yes.. I would like to see it layed out like this for the source tree...
  8395.  
  8396. python/src/
  8397. python/src/h/
  8398. python/src/lib/modules/
  8399. python/src/lib/objects/
  8400. python/src/lib/parser/
  8401. python/src/lib/h/
  8402. python/src/optional/
  8403. python/src/optional/package_name/
  8404. python/lib/          /* This is where the libpython.a file gets put */
  8405. python/include/      /* each makefile when given the "install" flag puts */
  8406.                      /* "external" header files here */
  8407. python/bin/          /* This is where the executables gets put */
  8408. python/doc/
  8409. python/samples/
  8410. python/support/lib/  /* This is what the current 'lib' directory would become */
  8411.  
  8412. Each of the directories in src/lib/* and src/optional/* would have
  8413. it's own makefile. Thre would be a toplevel makefile in src that would
  8414. call each of the other makefiles...
  8415.  
  8416.  
  8417. just my ideas...
  8418.  
  8419. Lance Ellinghouse
  8420. lance@markv.com
  8421.  
  8422. 
  8423. 
  8424. Received: from newton.ncsa.uiuc.edu by charon.cwi.nl with SMTP
  8425.     id AA25501 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 17:34:22 +0200
  8426. Received: from void.ncsa.uiuc.edu by newton.ncsa.uiuc.edu with SMTP id AA16386
  8427.   (5.65a/IDA-1.4.2 for Guido.van.Rossum@cwi.nl); Fri, 4 Jun 93 10:34:19 -0500
  8428. Return-Path: <liberte@ncsa.uiuc.edu>
  8429. Received: by void.ncsa.uiuc.edu (4.1/NCSA-4.1)
  8430.     id AA04350; Fri, 4 Jun 93 10:33:47 CDT
  8431. Date: Fri, 4 Jun 93 10:33:47 CDT
  8432. From: liberte@ncsa.uiuc.edu (Daniel LaLiberte)
  8433. Message-Id: <9306041533.AA04350@void.ncsa.uiuc.edu>
  8434. To: Guido.van.Rossum@cwi.nl
  8435. Subject: Re:  DISCUSSION: Naming conventions (for C code)
  8436.  
  8437. I agree you need to prefix C extern names with some code to protect
  8438. names.  Without this protection, name clashes can be very difficult
  8439. and cumbersome to get around.
  8440.  
  8441. dan
  8442. 
  8443. 
  8444. Replied: Sat, 05 Jun 1993 00:24:45 +0200
  8445. Replied: "Donald Beaudry <don@vicorp.com> "
  8446. Received: from relay1.UU.NET by charon.cwi.nl with SMTP
  8447.     id AA26048 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 17:53:15 +0200
  8448. Received: from vicorp.com (via vicorp.vicorp.com) by relay1.UU.NET with SMTP 
  8449.     (5.61/UUNET-internet-primary) id AA13056; Fri, 4 Jun 93 11:53:24 -0400
  8450. Received: from zippy.vicorp.com by vicorp.com (4.1/SMI-4.1)
  8451.     id AA04729; Fri, 4 Jun 93 11:51:31 EDT
  8452. Date: Fri, 4 Jun 93 11:51:31 EDT
  8453. From: Donald Beaudry <don@vicorp.com>
  8454. Message-Id: <9306041551.AA04729@vicorp.com>
  8455. To: Guido.van.Rossum@cwi.nl
  8456. Cc: python-list@cwi.nl
  8457. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Fri, 04 Jun 1993 01:08:39 +0200 <9306032308.AA06557=guido@voorn.cwi.nl>
  8458. Subject: DISCUSSION: Naming conventions (for C code)
  8459.  
  8460.  
  8461. What a great idea!
  8462.  
  8463.  
  8464. > The full naming scheme gives functions a name as follows:
  8465. > Py<Module>_<Function>, where <Module> is the (sometimes abbreviated)
  8466. > name of the module to which the function belongs (this may also be a
  8467. > basic type), and <Function> is a descriptive name for the function.
  8468. > The <Module> and <Function> parts use a mixed-case convention: each
  8469. > is spelled with an initial capital letter, and if they consist of
  8470. > multiple words each word has an initial capital.  Embedded underscores
  8471. > are not used except between <Module> and <Function>.  Some examples:
  8472.  
  8473. > PyList_Append
  8474. > PyList_GetItem
  8475. > PyList_New
  8476. > PyString_GetValue
  8477. > PyErr_SetStr
  8478.  
  8479. This is fine for all of the built in objects types but I would like to
  8480. suggest a slight variation for use with extension modules.  Each
  8481. extension module should have a short abbreviation which is then
  8482. inserted between the Py and the object name.  Using this convention
  8483. will allow one extention module to define objects with the same as
  8484. another extention module with out having to worry name collisions.
  8485. For example, Motif defines a string type which when wrapped by a
  8486. Python object should be called PyXmString.  Any other objects added by
  8487. the Xm module should be name in a similar manner, PyXmFontList is
  8488. another example.
  8489.  
  8490.  
  8491. > Global variables are named using similar conventions, e.g.
  8492.  
  8493. > PyType_List
  8494. > Py_ZeroDivisionError
  8495.  
  8496. I suppose that we have to have a naming convention for global
  8497. variables though I believe that their use should be strongly
  8498. discouraged.  Often they are unavoidable and in these cases they
  8499. should not be part of the public interface to the module in which they
  8500. are declared.  Rather, they should be named with a leading underscore
  8501. to indicate that they are private to the module and the module should
  8502. provide a procedural interface to them.  If performance is crucial
  8503. then this interface could take the form for a macro or two.
  8504.  
  8505.  
  8506. > Functions and variables that have to be global for some reason but are
  8507. > not part of the official interface have an initial underscore, e.g.
  8508.  
  8509. > _Py_RefTotal
  8510.  
  8511. This rule should also apply to any name that is not part of the
  8512. official interface.  Often it is useful to define structure or macros
  8513. that need to be shared by the files of a module, but are of no use to
  8514. the user of the module.
  8515.  
  8516.  
  8517. > Macros with arguments are named like functions, e.g.:
  8518.  
  8519. > Py_IsList
  8520. > Py_IncRef
  8521.  
  8522. I think that the distinction here should not be based on the existance
  8523. of arguments, but on the usage of the arguments.  If the macro acts
  8524. like, and can be replaced by a function then it should be named like a
  8525. function.  This is an important distinction since some macros are not
  8526. very well behaved and evaluate their arguments more than once, or they
  8527. do what cannot be done by a function, like statically initialize a
  8528. structure (OB_HEAD).  These non-function macros should be named
  8529. entirely in capitals with underscores seperating the words.
  8530.  
  8531.  
  8532. > Note that the current system has a number of structures that are not
  8533. > covered by typedefs.  These will be given typedef names.
  8534.  
  8535. Good.
  8536.  
  8537.  
  8538. > Also note that pointer types will continue to be written with the "*"
  8539. > notation, e.g. "PyObject *".  Pointers in C have sufficiently special
  8540. > semantics to make it important in practice to know whether a
  8541. > particular variable is a pointer; e.g. Python frequently uses casts
  8542. > between various object pointers.
  8543.  
  8544. Using this conventions will make it less convienent to use a very
  8545. useful information hiding trick.  Often, the definition of a structure
  8546. only needs to be known within the module that uses it.  The public
  8547. header file can then declare a typedef as a pointer to the structure
  8548. without specifying the structure at all.  Using this convention will
  8549. either force all structure defination to be exposed in the public
  8550. header files.
  8551.  
  8552. I think that a better approach is to define all stuctures with a
  8553. typedef name that ends with the suffix 'Struct', (or 'Rec' as Xt
  8554. does).  And then use a typedef to create a pointer type for that
  8555. structure.  The name should be the same as the structure minus the
  8556. suffix.  Now, header files can declare the same pointer type without
  8557. having access to the actual structure definition.  It is true that
  8558. this hides the fact the the type is a pointer, but whenever the type
  8559. is used outside of the module of its defination, only the public
  8560. interface functions should be used to access the type, thus the
  8561. question of whether or not it is a pointer becomes irrelevant.
  8562.  
  8563.  
  8564. > Header files will follow the conventions for typedef names, e.g.
  8565.  
  8566. > "PyList.h"
  8567.  
  8568. I would rather see header files put into a seperate directory, for a
  8569. couple of reasons.  First, it helps to keep the name of the header
  8570. file short.  On many systems, this is very important.  And second, it
  8571. makes it possible to distinguish public header file from private
  8572. header files.  That is, only public header files will be moved
  8573. (linked, copied, whatever) into the public area.  All private headers
  8574. could be kept with the source that needs them.  So, include directives
  8575. would end up looking somthing like this:
  8576.  
  8577.     #include <Py/List.h>
  8578.     #include <PyXt/Widget.h>
  8579.     #include <PyXm/String.h>
  8580.  
  8581.  
  8582. > A header named "Python.h" will collect almost all useful headers.
  8583.  
  8584. When it comes to header file inclusion, I have a simple rule that I
  8585. like to follow: "If you use it, include it."  In other words, if your
  8586. source uses any of the functionality or types provided by a header
  8587. file it should explicitly include that header file.  This rule also
  8588. applies to header files that use types defined in other header files.
  8589. Also, you should not assume that a given header file includes any
  8590. other header file for you.  This implies that all header files should
  8591. guard against multiple inclusion by wrappign themselves in a
  8592. preprocessor directive like this.
  8593.  
  8594.     #ifndef PyHEADER_FILE_H
  8595.     #define PyHEADER_FILE_H
  8596.  
  8597.         <text of header file>
  8598.  
  8599.     #endif
  8600.  
  8601. Unnecessary inclusion of header files lead to unnecessary
  8602. dependencies.  And unnecessary dependencies lead to unnecessary
  8603. compilation.  Unnecessary compliations lead to unnecessarily long
  8604. compilation times.  And I hate unnecessarily long compile times.
  8605.  
  8606.  
  8607. > It may be possible to introduce other changes as well, e.g. changes to
  8608. > the source tree: I might separate the .h files from the .c files,
  8609. > separate optional modules from the required part of the interpreter,
  8610. > move the parser generator to its own directory.  (Anything else?)
  8611.  
  8612. The seperation of optional from the required would be great.  
  8613.  
  8614. I would also like to see this as an opportunity to remove many of the
  8615. abbreviation currently in use.  Sure abbreviation are easy to type but
  8616. I find them difficult to read.  If used at all, I would only like to
  8617. see them on the left hand side of the underscore (assuming the naming
  8618. scheme described in the proposal) and only when that part of the name
  8619. starts to get obnoxishly long.
  8620.  
  8621.     --Don
  8622. ______     ______  
  8623. \_\_\_\   /#/#/#/  
  8624.  \_\_\_\ ______    
  8625.   \_\_\_V#/#/#/    Donald Beaudry                      don@vicorp.com        
  8626.    \_\_/#/#/#/     V. I. Corporation                   uunet!vicorp!don  
  8627.     \_/#/#/#/      47 Pleasant Street           PHONE: (413) 586-4144        
  8628.      V#/#/#/       Northampton, MA 01060    FAX:   (413) 586-3805        
  8629.  
  8630.  
  8631.  
  8632.       
  8633.       
  8634.       
  8635. 
  8636. 
  8637. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  8638.     id AA26421 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 18:02:44 +0200
  8639. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  8640.     id AA01611; Fri, 4 Jun 93 09:04:14 -0700
  8641. Received: by eng2.sequent.com (5.65/1.34)
  8642.     id AA13404; Fri, 4 Jun 93 09:02:30 -0700
  8643. Message-Id: <9306041602.AA13404@eng2.sequent.com>
  8644. To: lance@markv.com
  8645. Cc: Guido.van.Rossum@cwi.nl, python-list@cwi.nl
  8646. Subject: Re: DISCUSSION: Naming conventions (for C code)
  8647. Priority: Normal
  8648. Precedence: first-class
  8649. Organization: Sequent Computer Systems, Inc.
  8650.           Service Technology - MailStop: WIL2-610
  8651.           15450 S.W. Koll Parkway
  8652.           Beaverton, OR  97006-6063
  8653. X-Phone: (503) 578-4404
  8654. X-Fax: (503) 578-4540
  8655. X-Uucp: ...!uunet!sequent!jaap
  8656. X-Internet: jaap@sequent.com
  8657. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  8658.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  8659.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  8660. In-Reply-To: Lance Ellinghouse's message of Fri, 04 Jun 1993 08:06:50 -0700.
  8661.              <9306040806.aa29166@hermix.markv.com> 
  8662. Date: Fri, 04 Jun 1993 09:02:29 -0700
  8663. From: Jaap Vermeulen <jaap@sequent.com>
  8664.  
  8665.  
  8666. I agree with Lance and Jose. Except... :-)
  8667.  
  8668. | Yes.. I would like to see it layed out like this for the source tree...
  8669. ...
  8670. | python/lib/          /* This is where the libpython.a file gets put */
  8671. | python/include/      /* each makefile when given the "install" flag puts */
  8672. |                      /* "external" header files here */
  8673. | python/bin/          /* This is where the executables gets put */
  8674. | python/doc/
  8675. | python/samples/
  8676. | python/support/lib/  /* This is what the current 'lib' directory would become
  8677.      */
  8678.  
  8679. Here I disagree.  The python libraries are true libraries and should be
  8680. treated as such.  Therefore, they should be placed in
  8681. 'python/lib/python' IMO.  This would follow the same conventions as
  8682. '/usr' or '/usr/local'. (Picky, picky).
  8683.  
  8684.     -Jaap-
  8685. --
  8686. Jaap Vermeulen                    +--------------------------+
  8687.                         | Sequent Computer Systems |
  8688.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  8689.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  8690. 
  8691. 
  8692. Received: from relay2.UU.NET by charon.cwi.nl with SMTP
  8693.     id AA27697 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 18:46:10 +0200
  8694. Received: from spool.uu.net (via LOCALHOST) by relay2.UU.NET with SMTP 
  8695.     (5.61/UUNET-internet-primary) id AA01083; Fri, 4 Jun 93 12:46:24 -0400
  8696. Received: from island.UUCP by spool.uu.net with UUCP/RMAIL
  8697.     (queueing-rmail) id 124626.29833; Fri, 4 Jun 1993 12:46:26 EDT
  8698. Received: from bali.island.com by island.COM (4.1/SMI-4.1)
  8699.     id AA03610; Fri, 4 Jun 93 09:20:41 PDT
  8700. Received: by bali.island.com (4.1/SMI-4.1)
  8701.     id AA02422; Fri, 4 Jun 93 09:20:50 PDT
  8702. Date: Fri, 4 Jun 93 09:20:50 PDT
  8703. From: erik@bali.island.COM (Erik de Bueger)
  8704. Message-Id: <9306041620.AA02422@bali.island.com>
  8705. To: Guido.van.Rossum@cwi.nl
  8706. Subject: Re: DISCUSSION: Naming conventions (for C code)
  8707.  
  8708. Good Idea!
  8709.  
  8710. We are planning on incorporating python in our applications, and
  8711. this will avoid name clashes for sure (names like 'object' are very
  8712. much likely to be used elsewhere).
  8713.  
  8714. Your proposal about the naming sounds fine to me.
  8715.  
  8716. Erik de Bueger
  8717. Island Graphics Corporation
  8718. 
  8719. 
  8720. Replied: Sat, 05 Jun 1993 00:06:46 +0200
  8721. Replied: "Gerry Stringer <gerry@camscan.co.uk> "
  8722. Received: from eros.uknet.ac.uk by charon.cwi.nl with SMTP
  8723.     id AA02432 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 20:29:35 +0200
  8724. Received: from camscan.co.uk by eros.uknet.ac.uk with UUCP 
  8725.           id <sg.13109-0@eros.uknet.ac.uk>; Fri, 4 Jun 1993 19:29:32 +0100
  8726. Received: from electra.camscan.co.uk by star.camscan.co.uk;
  8727.           Fri, 4 Jun 93 19:24:26 BST
  8728. From: Gerry Stringer <gerry@camscan.co.uk>
  8729. Date: Fri, 4 Jun 93 19:24:30 BST
  8730. Message-Id: <21038.9306041824@electra.camscan.co.uk>
  8731. To: python-list@cwi.nl
  8732. Subject: pyhon & C++
  8733.  
  8734.  
  8735.  
  8736. There's been a sudden little flareup of mail on this list so I thought I might share some progress and raise a few small questions.
  8737.  
  8738.  
  8739. Overview:
  8740.  
  8741. We've reached the stage in our project where we need an interpreter front end (ddoesn't everyone) for user scripting/ customisation. I'm also getting a little disenchanted with the speed of C++ compilation so I'm looking for the possibility  of the interpreter being used as a replacement for some C++.
  8742.  
  8743. Python seemed the obvious choice to fit the bill because:
  8744.  
  8745.  1. there's a good chance a punter,I mean customer, could understand the syntax ie. not too hieroglyphic with lots of braces etc.
  8746.  
  8747.  2. there's a reasonable match between Python and C++
  8748.  
  8749. Pythongen:
  8750.  
  8751. We've got the classic problem of interfacing to lots of existing code (about 400,000 lines of code and headers) hence the obvious move of writing a 'stub generator' which, given a much cut down class description can generate all the necessary code to be able to call the class methods from python. We've done this by writing a utility called pythongen.
  8752.   
  8753. eg. given a file "PSessionApplication.pgen" containing:
  8754.  
  8755. #include "../PSessionApplication/PSessionApplication.h"
  8756. #include "../session.h"
  8757. #include "String.h"
  8758.  
  8759. class PSessionApplication ;
  8760.  
  8761. Constructor = {|<CONSPTR>| = sessionapp ;};
  8762.  
  8763. void savetoDB(String asname) ;
  8764. void startprog(char* ptypename,int nargs,char* [nargs]) ;
  8765. String get_save_name() ;
  8766.  
  8767. After running pythongen on the file and the usual compilation tedium I can do
  8768.  
  8769.     import PSessionApplication
  8770.     session.startprog('someprogram',3,['-Wp','527','157']) 
  8771.  
  8772.  
  8773. this is I actuallly 
  8774. 
  8775. 
  8776. Replied: Sat, 05 Jun 1993 00:03:08 +0200
  8777. Replied: "Lance Ellinghouse <lance@markv.com> python-list"
  8778. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  8779.     id AA05288 (5.65b/3.8/CWI-Amsterdam); Fri, 4 Jun 1993 21:29:16 +0200
  8780. From: Lance Ellinghouse <lance@markv.com>
  8781. X-Mailer: SCO System V Mail (version 3.2)
  8782. To: python-list@cwi.nl
  8783. Subject: unix signal() handeling...
  8784. Date: Fri, 4 Jun 93 12:28:48 PDT
  8785. Message-Id:  <9306041228.aa23487@hermix.markv.com>
  8786.  
  8787. Has anyone created a set of routines to attach arbitrary signal
  8788. handlers to signals from inside Python?
  8789.  
  8790. What I would like to be able to do is catch signals inside python
  8791. and then call python code to handle the signals.
  8792.  
  8793. Lance Ellinghouse
  8794. lance@markv.com
  8795. 
  8796. 
  8797. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  8798.     id AA10137 (5.65b/3.8/CWI-Amsterdam); Sat, 5 Jun 1993 00:03:11 +0200
  8799. Received: by voorn.cwi.nl with SMTP
  8800.     id AA09070 (5.65b/3.8/CWI-Amsterdam); Sat, 5 Jun 1993 00:03:08 +0200
  8801. Message-Id: <9306042203.AA09070=guido@voorn.cwi.nl>
  8802. To: Lance Ellinghouse <lance@markv.com>
  8803. Cc: python-list@cwi.nl
  8804. Subject: Re: unix signal() handeling... 
  8805. In-Reply-To: Your message of "Fri, 04 Jun 1993 12:28:48 MDT."
  8806.              <9306041228.aa23487@hermix.markv.com> 
  8807. From: Guido.van.Rossum@cwi.nl
  8808. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  8809. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  8810. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  8811. Date: Sat, 05 Jun 1993 00:03:08 +0200
  8812. Sender: Guido.van.Rossum@cwi.nl
  8813.  
  8814. > Has anyone created a set of routines to attach arbitrary signal
  8815. > handlers to signals from inside Python?
  8816. > What I would like to be able to do is catch signals inside python
  8817. > and then call python code to handle the signals.
  8818.  
  8819. I haven't heard of anyone trying it yet.  Can you give an example of
  8820. how this would be useful?
  8821.  
  8822. In any case you would have to handle them in a similar way as the
  8823. KeyboardInterrupt exception is currently handled: the real (C) signal
  8824. handler only sets a flag that the signal has arrived, and then later
  8825. the interpreter checks this flag (possibly after each (virtual)
  8826. instruction -- currently it's done only every few instructions) and
  8827. invokes the code that handles the signal.  I suppose you could set it
  8828. up so that if the handler returns the interpreter continues where it
  8829. left off, while if the handler raises an exception the interpreter
  8830. passes the exception on.  KeyboardInterrupt could then be made a
  8831. special case of this.
  8832.  
  8833. Note that you won't be able to catch program bugs in the Python
  8834. interpreter this way (since they must be handled synchronously).
  8835.  
  8836. There is also the problem that not all wrappers around blocking system
  8837. calls (or blocking library calls) will will yield return when a signal
  8838. handler is called, so the Python signal handling may wait until the
  8839. call returns normally -- this is usually not what you want.
  8840.  
  8841. I'm sorry...
  8842.  
  8843. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  8844. 
  8845. 
  8846. To: Lance Ellinghouse <lance@markv.com>
  8847. cc: python-list
  8848. Subject: Re: unix signal() handeling... 
  8849. In-reply-to: Your message of "Fri, 04 Jun 1993 12:28:48 MDT."
  8850.              <9306041228.aa23487@hermix.markv.com> 
  8851. From: Guido.van.Rossum@cwi.nl
  8852. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  8853. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  8854. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  8855. Date: Sat, 05 Jun 1993 00:03:08 +0200
  8856. Sender: guido
  8857.  
  8858. > Has anyone created a set of routines to attach arbitrary signal
  8859. > handlers to signals from inside Python?
  8860. > What I would like to be able to do is catch signals inside python
  8861. > and then call python code to handle the signals.
  8862.  
  8863. I haven't heard of anyone trying it yet.  Can you give an example of
  8864. how this would be useful?
  8865.  
  8866. In any case you would have to handle them in a similar way as the
  8867. KeyboardInterrupt exception is currently handled: the real (C) signal
  8868. handler only sets a flag that the signal has arrived, and then later
  8869. the interpreter checks this flag (possibly after each (virtual)
  8870. instruction -- currently it's done only every few instructions) and
  8871. invokes the code that handles the signal.  I suppose you could set it
  8872. up so that if the handler returns the interpreter continues where it
  8873. left off, while if the handler raises an exception the interpreter
  8874. passes the exception on.  KeyboardInterrupt could then be made a
  8875. special case of this.
  8876.  
  8877. Note that you won't be able to catch program bugs in the Python
  8878. interpreter this way (since they must be handled synchronously).
  8879.  
  8880. There is also the problem that not all wrappers around blocking system
  8881. calls (or blocking library calls) will will yield return when a signal
  8882. handler is called, so the Python signal handling may wait until the
  8883. call returns normally -- this is usually not what you want.
  8884.  
  8885. I'm sorry...
  8886.  
  8887. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  8888. 
  8889. 
  8890. To: Donald Beaudry <don@vicorp.com>
  8891. Subject: Re: DISCUSSION: Naming conventions (for C code) 
  8892. In-reply-to: Your message of "Fri, 04 Jun 1993 11:51:31 MDT."
  8893.              <9306041551.AA04729@vicorp.com> 
  8894. From: Guido.van.Rossum@cwi.nl
  8895. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  8896. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  8897. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  8898. Date: Sat, 05 Jun 1993 00:24:45 +0200
  8899. Sender: guido
  8900.  
  8901. You say many wise words.  Just one thing right now on an issue where I
  8902. won't give up easily...
  8903.  
  8904. > Using this conventions will make it less convienent to use a very
  8905. > useful information hiding trick.  Often, the definition of a structure
  8906. > only needs to be known within the module that uses it.  The public
  8907. > header file can then declare a typedef as a pointer to the structure
  8908. > without specifying the structure at all.  Using this convention will
  8909. > either force all structure defination to be exposed in the public
  8910.   ^^^^^^
  8911. > header files.
  8912.  
  8913. Actually, it is completely legal in C (even pre-ANSI C!) to do things
  8914. like
  8915.  
  8916.     struct unknown_tag *p; /* pointer to unknown structure */
  8917.  
  8918. and
  8919.  
  8920.     typedef struct unknown_tag opaque_t; /* opaque typedef */
  8921.  
  8922. where "struct unknown_tag" is not defined in the current file.
  8923.  
  8924. The latter makes it possible to declare pointers to opaque_t objects
  8925. but not to declare opaque_t objects (then the compiler will say
  8926. "unknown size" or so).
  8927.  
  8928. As a compromise I can see defining both, say, PyObject and PyObjectPtr,
  8929. so I can write "PyObject *p" and you can write "PyObjectPtr p".  I can
  8930. read the latter style but prefer to write the former; I suppose for
  8931. you it's the other way around :-)
  8932.  
  8933. (I'm still waiting for the "or" part of your last sentence here...)
  8934.  
  8935. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  8936. 
  8937. 
  8938. Replied: Sat, 05 Jun 1993 10:33:05 +0200
  8939. Replied: "Lance Ellinghouse <lance@markv.com> "
  8940. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  8941.     id AA17568 (5.65b/3.8/CWI-Amsterdam); Sat, 5 Jun 1993 01:55:28 +0200
  8942. From: Lance Ellinghouse <lance@markv.com>
  8943. X-Mailer: SCO System V Mail (version 3.2)
  8944. To: Guido.van.Rossum@cwi.nl
  8945. Subject: Re: unix signal() handeling...
  8946. Cc: python-list@cwi.nl
  8947. Date: Fri, 4 Jun 93 16:55:06 PDT
  8948. Message-Id:  <9306041655.aa15016@hermix.markv.com>
  8949.  
  8950. >> Has anyone created a set of routines to attach arbitrary signal
  8951. >> handlers to signals from inside Python?
  8952. >> 
  8953. >> What I would like to be able to do is catch signals inside python
  8954. >> and then call python code to handle the signals.
  8955. >
  8956. >I haven't heard of anyone trying it yet.  Can you give an example of
  8957. >how this would be useful?
  8958.  
  8959. Ok.. For my example.. I have a single program that manages 
  8960. ~40 other programs. One thing I would like to do is be able to set
  8961. a signal handler so that it would catch SIGCLD and then run
  8962. another instance of the program that quit. This is easy to do in
  8963. the C code, BUT I don't want to! I want it to be 100% changable
  8964. in Python code (thus more flexible). I COULD poll each process with
  8965. posix.kill(0,pid) but I really prefer NOT to have to poll..
  8966. This program will be doing enough keeping up with all the processing
  8967. it has to do on the side..
  8968.  
  8969. Another instance would be to catch SIGHUP so that you could monitor 
  8970. a modem line and have Python code deal with a person hanging up on the
  8971. line..
  8972.  
  8973. >In any case you would have to handle them in a similar way as the
  8974. >KeyboardInterrupt exception is currently handled: the real (C) signal
  8975. >handler only sets a flag that the signal has arrived, and then later
  8976. >the interpreter checks this flag (possibly after each (virtual)
  8977. >instruction -- currently it's done only every few instructions) and
  8978. >invokes the code that handles the signal.  I suppose you could set it
  8979. >up so that if the handler returns the interpreter continues where it
  8980. >left off, while if the handler raises an exception the interpreter
  8981. >passes the exception on.  KeyboardInterrupt could then be made a
  8982. >special case of this.
  8983.  
  8984. This sounds reasonable.. I would be happy to code it.. (signal handling)
  8985. Where should I start looking?
  8986.  
  8987. >Note that you won't be able to catch program bugs in the Python
  8988. >interpreter this way (since they must be handled synchronously).
  8989.  
  8990. Not wanting to..
  8991.  
  8992. >There is also the problem that not all wrappers around blocking system
  8993. >calls (or blocking library calls) will will yield return when a signal
  8994. >handler is called, so the Python signal handling may wait until the
  8995. >call returns normally -- this is usually not what you want.
  8996.  
  8997. This should be ok in most cases.. at least the ones I am dealing with
  8998.  
  8999. Lance Ellinghouse
  9000. lance@markv.com
  9001.  
  9002. 
  9003. 
  9004. Replied: Sat, 05 Jun 1993 10:36:18 +0200
  9005. Replied: "Jaap Vermeulen <jaap@sequent.com> "
  9006. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  9007.     id AA20122 (5.65b/3.8/CWI-Amsterdam); Sat, 5 Jun 1993 02:24:47 +0200
  9008. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  9009.     id AA19269; Fri, 4 Jun 93 17:26:21 -0700
  9010. Received: by eng2.sequent.com (5.65/1.34)
  9011.     id AA22703; Fri, 4 Jun 93 17:24:39 -0700
  9012. Message-Id: <9306050024.AA22703@eng2.sequent.com>
  9013. To: lance@markv.com
  9014. Cc: Guido.van.Rossum@cwi.nl, python-list@cwi.nl
  9015. Subject: Re: unix signal() handeling...
  9016. Priority: Normal
  9017. Precedence: first-class
  9018. Organization: Sequent Computer Systems, Inc.
  9019.           Service Technology - MailStop: WIL2-610
  9020.           15450 S.W. Koll Parkway
  9021.           Beaverton, OR  97006-6063
  9022. X-Phone: (503) 578-4404
  9023. X-Fax: (503) 578-4540
  9024. X-Uucp: ...!uunet!sequent!jaap
  9025. X-Internet: jaap@sequent.com
  9026. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  9027.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  9028.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  9029. In-Reply-To: Lance Ellinghouse's message of Fri, 04 Jun 1993 16:55:06 -0700.
  9030.              <9306041655.aa15016@hermix.markv.com> 
  9031. Date: Fri, 04 Jun 1993 17:24:38 -0700
  9032. From: Jaap Vermeulen <jaap@sequent.com>
  9033.  
  9034.  
  9035. | Ok.. For my example.. I have a single program that manages 
  9036. | ~40 other programs. One thing I would like to do is be able to set
  9037.  
  9038. I had to deal with ~200 to ~400 processes that I would keep going all
  9039. the time.  I would just do a wait, see which processes exited and
  9040. restart it.
  9041.  
  9042. The code would something look like:
  9043.  
  9044. ...
  9045. pid = posix.fork()
  9046. if pid:
  9047.     processes[`pid`] = ...
  9048. else:
  9049.     ...
  9050. ...
  9051. pid, exitcode = posix.wait()
  9052. ... = processes[`pid`]
  9053.  
  9054. What I did in the '...' is that I had a object that would manage a
  9055. process.  You could start a process with arguments etc., or you could
  9056. restart (it would remember the arguments), or you wait for it
  9057. specifically, or you could kill it etc.
  9058.  
  9059. Good luck,
  9060.  
  9061.     -Jaap-
  9062. --
  9063. Jaap Vermeulen                    +--------------------------+
  9064.                         | Sequent Computer Systems |
  9065.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  9066.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  9067. 
  9068. 
  9069. Replied: Wed, 16 Jun 1993 10:22:09 +0200
  9070. Replied: "Lance Ellinghouse <lance@markv.com> "
  9071. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  9072.     id AA14630 (5.65b/3.8/CWI-Amsterdam); Wed, 16 Jun 1993 03:03:12 +0200
  9073. From: Lance Ellinghouse <lance@markv.com>
  9074. X-Mailer: SCO System V Mail (version 3.2)
  9075. To: python-list@cwi.nl
  9076. Subject: incorrect prototypes??
  9077. Date: Tue, 15 Jun 93 18:02:38 PDT
  9078. Message-Id:  <9306151802.aa23797@hermix.markv.com>
  9079.  
  9080.  
  9081. Is there a reason that things like getlistsize() take
  9082. a 'object *' instead of a 'listobject *' ???? 
  9083.  
  9084. This does not make much sense...
  9085.  
  9086. Can this be added to the "Clean Up List"???
  9087.  
  9088. Lance Ellinghouse
  9089. lance@markv.com
  9090. 
  9091. 
  9092. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  9093.     id AA00357 (5.65b/3.8/CWI-Amsterdam); Wed, 16 Jun 1993 12:47:40 +0200
  9094. Received: by voorn.cwi.nl with SMTP
  9095.     id AA16382 (5.65b/3.8/CWI-Amsterdam); Wed, 16 Jun 1993 12:47:40 +0200
  9096. Message-Id: <9306161047.AA16382=guido@voorn.cwi.nl>
  9097. To: python-list@cwi.nl
  9098. Subject: Re: incorrect prototypes?? 
  9099. In-Reply-To: Your message of "Tue, 15 Jun 1993 18:02:38 MDT."
  9100.              <9306151802.aa23797@hermix.markv.com> 
  9101. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9102. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9103. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9104. Date: Wed, 16 Jun 1993 12:47:40 +0200
  9105. From: Guido van Rossum <Guido.van.Rossum@cwi.nl>
  9106.  
  9107. > Is there a reason that things like getlistsize() take
  9108. > a 'object *' instead of a 'listobject *' ???? 
  9109. > This does not make much sense...
  9110.  
  9111. This was done on purpose, because in many cases one has received an
  9112. "object*" (e.g. as an argument), detects that it is a list by using
  9113. "is_listobject()", and then wants to access it as a list.  If all the
  9114. list-specific functions took a "listobject*" as argument, one would
  9115. either have to copy the object into a local variable of that type, or
  9116. use a cast on each call.  I am not very fond of casts (since the
  9117. compiler will happily cast e.g. a "char*" to "listobject*") so I
  9118. prefer to minimize their number.
  9119.  
  9120. It's true that now there's a cast inside listgetsize(), but that's one
  9121. cast per function definition instead of one cast per function call.
  9122. Also note that getlistsize() tests its argument for list-ness.
  9123. Strictly spoken this should be redundant, but many people (including
  9124. me!) sometimes write sloppy code that doesn't always check the types
  9125. of objects passing through a function.  The function err_badcall()
  9126. (used in such occasions) currently raises an exception, but can easily
  9127. be changed to call abort(), which pin-points the cause of the error
  9128. much better than a segmentation violation caused by accessing a
  9129. non-list as if it were a list...
  9130.  
  9131. Finally note that at least it's reasonably consistent: newlistobject()
  9132. returns an "object*", and getlistsize() takes one...
  9133.  
  9134. > Can this be added to the "Clean Up List"???
  9135.  
  9136. Even if I did agree that it was a "good thing", cleaning this up would
  9137. be a major, boring coding effort, because (unlike identifier changes)
  9138. it can't be automated (or the automation would be as least as much
  9139. work).
  9140.  
  9141. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9142. 
  9143. 
  9144. Replied: Fri, 18 Jun 1993 17:11:02 +0200
  9145. Replied: "Lance Ellinghouse <lance@markv.com> "
  9146. Replied: Fri, 18 Jun 1993 16:58:14 +0200
  9147. Replied: "Lance Ellinghouse <lance@markv.com> python-list"
  9148. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  9149.     id AA10360 (5.65b/3.8/CWI-Amsterdam); Wed, 16 Jun 1993 18:29:01 +0200
  9150. From: Lance Ellinghouse <lance@markv.com>
  9151. X-Mailer: SCO System V Mail (version 3.2)
  9152. To: Guido.van.Rossum@cwi.nl
  9153. Subject: Re: incorrect prototypes??
  9154. Date: Wed, 16 Jun 93 9:28:07 PDT
  9155. Message-Id:  <9306160928.aa18599@hermix.markv.com>
  9156.  
  9157. >> Is there a reason that things like getlistsize() take
  9158. >> a 'object *' instead of a 'listobject *' ???? 
  9159. >> 
  9160. >> This does not make much sense...
  9161. >
  9162. >This was done on purpose, because in many cases one has received an
  9163. >"object*" (e.g. as an argument), detects that it is a list by using
  9164. >"is_listobject()", and then wants to access it as a list.  If all the
  9165. >list-specific functions took a "listobject*" as argument, one would
  9166. >either have to copy the object into a local variable of that type, or
  9167. >use a cast on each call.  I am not very fond of casts (since the
  9168. >compiler will happily cast e.g. a "char*" to "listobject*") so I
  9169. >prefer to minimize their number.
  9170.  
  9171. I do not use 'object *' at all in my code. If I did, all would
  9172. work fine, but then the compiler would not warn me that I am
  9173. passing things where they should not be. Currently I am
  9174. having to cast everything because they are NOT prototyped using
  9175. 'listobject *'. :( Looks like different programmig styles have
  9176. clashed. Oh well.. 
  9177.  
  9178. >It's true that now there's a cast inside listgetsize(), but that's one
  9179. >cast per function definition instead of one cast per function call.
  9180. >Also note that getlistsize() tests its argument for list-ness.
  9181. >Strictly spoken this should be redundant, but many people (including
  9182. >me!) sometimes write sloppy code that doesn't always check the types
  9183. >of objects passing through a function.  The function err_badcall()
  9184. >(used in such occasions) currently raises an exception, but can easily
  9185. >be changed to call abort(), which pin-points the cause of the error
  9186. >much better than a segmentation violation caused by accessing a
  9187. >non-list as if it were a list...
  9188.  
  9189. All functions should test for the correct type being passed in.
  9190. This is a given. I would feel the code was VERY broken if it did NOT 
  9191. check for this. By always using the correct type, 'listobject *' or
  9192. 'tupleobject *', instead of the generic 'object *', it also makes 
  9193. programs easier to tell what is going on (at least I think so..), but then
  9194. I have to deal with ANSI compilers that complain on every function call
  9195. that I am passing the wrong type. So I either cast EVERYTHING (what a 
  9196. waste!) or I change the xxobject.h files (as I have done) to accept the
  9197. correct type. This will also force the compiler to give a warning/error
  9198. if I am passing in a non-typed object, i.e. 'object *', instead of the
  9199. correct one. Makes you look over your code a little more.
  9200.  
  9201. >Finally note that at least it's reasonably consistent: newlistobject()
  9202. >returns an "object*", and getlistsize() takes one...
  9203.  
  9204. I think this is wrong. newlistobject() should return a 'listobject *' 
  9205. instead of a 'object *'. It may be consistent, but I think it is wrong.
  9206. If I am the only one in the world that does feel this way, I will
  9207. shut my mouth and keep quiet.
  9208.  
  9209. Lance Ellinghouse
  9210. lance@markv.com
  9211.  
  9212. 
  9213. 
  9214. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  9215.     id AA22543 (5.65b/3.8/CWI-Amsterdam); Fri, 18 Jun 1993 16:58:14 +0200
  9216. Received: by voorn.cwi.nl with SMTP
  9217.     id AA24762 (5.65b/3.8/CWI-Amsterdam); Fri, 18 Jun 1993 16:58:14 +0200
  9218. Message-Id: <9306181458.AA24762=guido@voorn.cwi.nl>
  9219. To: Lance Ellinghouse <lance@markv.com>
  9220. Cc: python-list@cwi.nl
  9221. Subject: Re: incorrect prototypes?? 
  9222. In-Reply-To: Your message of "Wed, 16 Jun 1993 09:28:07 MDT."
  9223.              <9306160928.aa18599@hermix.markv.com> 
  9224. From: Guido.van.Rossum@cwi.nl
  9225. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9226. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9227. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9228. Date: Fri, 18 Jun 1993 16:58:14 +0200
  9229. Sender: Guido.van.Rossum@cwi.nl
  9230.  
  9231. [Lance sent me a private reply, probably by mistake (since I first
  9232. sent him a private reply by mistake).  I quote liberally from his reply.]
  9233.  
  9234. > I do not use 'object *' at all in my code. If I did, all would
  9235. > work fine, but then the compiler would not warn me that I am
  9236. > passing things where they should not be. Currently I am
  9237. > having to cast everything because they are NOT prototyped using
  9238. > 'listobject *'. :( Looks like different programmig styles have
  9239. > clashed. Oh well.. 
  9240.  
  9241. I don't see how you can live without "object*" in general.  (Of course
  9242. I don't know how much code you have and how general it is.)  Take for
  9243. instance a C function called from Python that takes a list of integers
  9244. as argument, and has to access the element.  Python's type system
  9245. makes it impossible to enforce that the list items are indeed
  9246. integers, so the function has to check this.  The code would look more
  9247. or less like this:
  9248.  
  9249.     object *
  9250.     sum_list(dummy, arg)
  9251.         object *dummy, *arg;
  9252.     {
  9253.         int i, n;
  9254.         long sum;
  9255.         if (arg == NULL || !is_listobject(args)) {
  9256.             err_set(TypeError);
  9257.             return NULL;
  9258.         }
  9259.         n = getlistsize(arg);
  9260.         sum = 0;
  9261.         for (i = 0; i < n; i++) {
  9262.             object *item = getlistitem(arg, i);
  9263.             if (!is_intobject(item)) {
  9264.                 err_set(TypeError);
  9265.                 return NULL;
  9266.             }
  9267.             sum = sum + getintitem(item);
  9268.         }
  9269.         return newintobject(sum);
  9270.     }
  9271.  
  9272. (Suppose this can be called directly as a function in a built-in
  9273. module.)
  9274.  
  9275. Now we don't *know* that arg is a list object until we've tested it,
  9276. so it would be lying to declare it as such.  The same holds for item.
  9277. Also, note that the function has to be declared object* even though
  9278. we know it will always return an intobject* (or NULL), since it has to
  9279. conform to the general prototype for built-in functions.  This means
  9280. that if newintobject() were declared to return intobject* instead of
  9281. object*, we would need another cast for the return value.
  9282.  
  9283. If Python were implemented in C++, things would be different: explicit
  9284. casts from specialized object types to generic object* would be
  9285. unnecessary, and casts from object* to any particular object type
  9286. could be handled differently (there's quite a nice C++ idiom for this
  9287. that combines the cast and the check for object type).  But we're
  9288. using plain C, and I maintain that having most functions take and
  9289. return object* and do some checking is the best compromise.  (It's
  9290. different in parts of the interpreter where objects' members are
  9291. accessed frequently; there the correct type must be used; but this is
  9292. not for general consumption...)
  9293.  
  9294. > All functions should test for the correct type being passed in.
  9295. > This is a given. I would feel the code was VERY broken if it did NOT 
  9296. > check for this.
  9297.  
  9298. No.  Functions shouldn't have to check when the type has already been
  9299. checked by the compiler.  The point is if every routine checked its
  9300. arguments, there would be a lot of redundant checking going on (since
  9301. often there are several levels of function calls passing each other
  9302. objects that have already been verified).  The function that casts an
  9303. object* to listobject* is responsible for only applying the cast if it
  9304. is valid.
  9305.  
  9306. > I think this is wrong. newlistobject() should return a 'listobject *' 
  9307. > instead of a 'object *'. It may be consistent, but I think it is wrong.
  9308. > If I am the only one in the world that does feel this way, I will
  9309. > shut my mouth and keep quiet.
  9310.  
  9311. Actually, I enjoy discussions like this, but so far few people have
  9312. joined in, so I am here on my own defending some questional
  9313. practice...
  9314.  
  9315. (Maybe they are still waiting for my revised name changing proposal?
  9316. Hold your breath, I'm working on it...)
  9317.  
  9318. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9319. 
  9320. 
  9321. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  9322.     id AA26445 (5.65b/3.8/CWI-Amsterdam); Fri, 18 Jun 1993 18:57:04 +0200
  9323. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  9324.     id AA09335; Fri, 18 Jun 93 09:58:16 -0700
  9325. Received: by eng2.sequent.com (5.65/1.34)
  9326.     id AA16533; Fri, 18 Jun 93 09:56:50 -0700
  9327. Message-Id: <9306181656.AA16533@eng2.sequent.com>
  9328. To: Guido.van.Rossum@cwi.nl
  9329. Cc: lance@markv.com, python-list@cwi.nl
  9330. Subject: Re: incorrect prototypes??
  9331. Priority: Normal
  9332. Precedence: first-class
  9333. Organization: Sequent Computer Systems, Inc.
  9334.           Service Technology - MailStop: WIL2-610
  9335.           15450 S.W. Koll Parkway
  9336.           Beaverton, OR  97006-6063
  9337. X-Phone: (503) 578-4404
  9338. X-Fax: (503) 578-4540
  9339. X-Uucp: ...!uunet!sequent!jaap
  9340. X-Internet: jaap@sequent.com
  9341. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  9342.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  9343.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  9344. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Fri, 18 Jun 1993 16:58:14 +0200.
  9345.              <9306181458.AA24762=guido@voorn.cwi.nl> 
  9346. Date: Fri, 18 Jun 1993 09:56:49 -0700
  9347. From: Jaap Vermeulen <jaap@sequent.com>
  9348.  
  9349.  
  9350. | Actually, I enjoy discussions like this, but so far few people have
  9351. | joined in, so I am here on my own defending some questional
  9352. | practice...
  9353.  
  9354. I think it's a matter of programming style for those routines that are
  9355. not part of the interface to the python engine.  Somewhere you have to
  9356. cast, and it is a question of semantics whether you do the check in the
  9357. caller or the callee.  Here it looks like getlistsize() serves the dual
  9358. role of checking its argument *and* returning the size.
  9359.  
  9360. Of course most of the callers don't use this feature and you'll end up
  9361. with a redundant check.  Either way, I think I would gravitate towards
  9362. Guido approach since I find it simpler and more elegant (casts are not
  9363. my favorite either), even if it means some redundant checks.
  9364.  
  9365.     -Jaap-
  9366. --
  9367. Jaap Vermeulen                    +--------------------------+
  9368.                         | Sequent Computer Systems |
  9369.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  9370.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  9371. 
  9372. 
  9373. Received: from relay1.UU.NET by charon.cwi.nl with SMTP
  9374.     id AA27633 (5.65b/3.8/CWI-Amsterdam); Fri, 18 Jun 1993 19:37:35 +0200
  9375. Received: from vicorp.com (via vicorp.vicorp.com) by relay1.UU.NET with SMTP 
  9376.     (5.61/UUNET-internet-primary) id AA18731; Fri, 18 Jun 93 13:37:24 -0400
  9377. Received: from zippy.vicorp.com by vicorp.com (4.1/SMI-4.1)
  9378.     id AA01391; Fri, 18 Jun 93 13:36:49 EDT
  9379. Date: Fri, 18 Jun 93 13:36:49 EDT
  9380. From: Donald Beaudry <don@vicorp.com>
  9381. Message-Id: <9306181736.AA01391@vicorp.com>
  9382. To: python-list@cwi.nl
  9383. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Fri, 18 Jun 1993 16:58:14 +0200 <9306181458.AA24762=guido@voorn.cwi.nl>
  9384. Subject: incorrect prototypes?? 
  9385.  
  9386. >> I think this is wrong. newlistobject() should return a 'listobject *' 
  9387. >> instead of a 'object *'. It may be consistent, but I think it is wrong.
  9388. >> If I am the only one in the world that does feel this way, I will
  9389. >> shut my mouth and keep quiet.
  9390.  
  9391. > Actually, I enjoy discussions like this, but so far few people have
  9392. > joined in, so I am here on my own defending some questional
  9393. > practice...
  9394.  
  9395. Well, I guess I should toss my opinion in so that Guido does not have
  9396. to feel alone.
  9397.  
  9398. I don't think that the practice of using object* for everything is
  9399. questionable at all.  I even think that it is necessary.  Python is a
  9400. dynamically typed language.  Since C does not support dynamic type
  9401. checking it is up to the programmer to do it.  Specifically, it is up
  9402. to the implementor of the object.  All objects should have a public
  9403. interface and that interface must check that object passed is really
  9404. of the same type as expected.  In fact, the static type of the object
  9405. (the C structure) should be hidden from the users of the object.  It
  9406. is up to the implementor of the object to decide what attributes are
  9407. visible and to provide an interface to those attributes.
  9408.  
  9409.  
  9410.     --Don
  9411. ______     ______  
  9412. \_\_\_\   /#/#/#/  
  9413.  \_\_\_\ ______    
  9414.   \_\_\_V#/#/#/    Donald Beaudry                      don@vicorp.com        
  9415.    \_\_/#/#/#/     V. I. Corporation                   uunet!vicorp!don  
  9416.     \_/#/#/#/      47 Pleasant Street           PHONE: (413) 586-4144        
  9417.      V#/#/#/       Northampton, MA 01060    FAX:   (413) 586-3805        
  9418.  
  9419.  
  9420.  
  9421.       
  9422.       
  9423.       
  9424. 
  9425. 
  9426. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  9427.     id AA29055 (5.65b/3.8/CWI-Amsterdam); Fri, 18 Jun 1993 20:11:55 +0200
  9428. To: python-list@cwi.nl
  9429. Subject: Prototypes..
  9430. Date: Fri, 18 Jun 93 11:10:41 PDT
  9431. From: lance@markv.com
  9432. Sender: lance@markv.com
  9433. Message-Id:  <9306181110.aa05123@hermix.markv.com>
  9434. Source-Info:  From (or Sender) name not authenticated.
  9435.  
  9436.  
  9437. Well since everyone seems to agree with the current style of prototypes,
  9438. I will just have to get used to it and use it. Not a major problem..
  9439.  
  9440. Sorry for wasting soo much bandwidth on this topic.
  9441.  
  9442. Lance Ellinghouse
  9443. lance@markv.com
  9444. 
  9445. 
  9446. Replied: Sat, 19 Jun 1993 10:55:03 +0200
  9447. Replied: "Doug Moen <dmoen@utcc.utoronto.ca> "
  9448. Received: from gpu.utcc.utoronto.ca by charon.cwi.nl with SMTP
  9449.     id AA27899 (5.65b/3.8/CWI-Amsterdam); Sat, 19 Jun 1993 06:09:02 +0200
  9450. Received: by gpu.utcc.utoronto.ca id <18552>; Sat, 19 Jun 1993 00:08:48 -0400
  9451. From: Doug Moen <dmoen@utcc.utoronto.ca>
  9452. To: python-list@cwi.nl
  9453. Subject: type casting and c++
  9454. Message-Id: <93Jun19.000848edt.18552@gpu.utcc.utoronto.ca>
  9455. Date:     Sat, 19 Jun 1993 00:08:37 -0400
  9456.  
  9457. > If Python were implemented in C++, things would be different: explicit
  9458. > casts from specialized object types to generic object* would be
  9459. > unnecessary, and casts from object* to any particular object type
  9460. > could be handled differently (there's quite a nice C++ idiom for this
  9461. > that combines the cast and the check for object type).
  9462.  
  9463. This sounds like a good argument for translating Python into C++.
  9464. Here's another: that business of explicitly managing reference counts
  9465. could be greatly simplified using C++ constructors and destructors.
  9466. This would make the job of writing extension modules less error prone.
  9467.  
  9468. Ignore for a moment the fact that it would be a lot of work,
  9469. and consider this: Python is written in C because C is ubiquitous.
  9470. Since Python began, C++ has become much more widely available.
  9471. There are now multiple PC and Mac compilers, and GNU seems to cover the
  9472. Unix platforms.  Is C++ now sufficiently widely available that converting
  9473. Python to C++ makes sense?
  9474. 
  9475. 
  9476. To: Doug Moen <dmoen@utcc.utoronto.ca>
  9477. Subject: Re: type casting and c++ 
  9478. In-reply-to: Your message of "Sat, 19 Jun 1993 00:08:37 MDT."
  9479.              <93Jun19.000848edt.18552@gpu.utcc.utoronto.ca> 
  9480. From: Guido.van.Rossum@cwi.nl
  9481. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9482. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9483. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9484. Date: Sat, 19 Jun 1993 10:55:03 +0200
  9485. Sender: guido
  9486.  
  9487. > This sounds like a good argument for translating Python into C++.
  9488. > Here's another: that business of explicitly managing reference counts
  9489. > could be greatly simplified using C++ constructors and destructors.
  9490. > This would make the job of writing extension modules less error prone.
  9491.  
  9492. I tried setting up a scheme for automatic reference counting C++ once
  9493. and soon found out that it incurs a lot more overhead than the way
  9494. it's done manually in C now.  The problem is that in many situations
  9495. you don't need to change a reference count because you don't
  9496. permanently store a copy of a pointer, you only "peek" at it.  A
  9497. simple-minded reference-counting pointer type in C++ won't know this
  9498. and will add referece count adjustments in many more places than
  9499. necessary.  When this happens at the lower levels it will really slow
  9500. things down.
  9501.  
  9502. > Ignore for a moment the fact that it would be a lot of work,
  9503. > and consider this: Python is written in C because C is ubiquitous.
  9504. > Since Python began, C++ has become much more widely available.
  9505. > There are now multiple PC and Mac compilers, and GNU seems to cover the
  9506. > Unix platforms.  Is C++ now sufficiently widely available that converting
  9507. > Python to C++ makes sense?
  9508.  
  9509. I have my doubts.  C++ is more widely available, but it is not by any
  9510. measure "ubiquitous".  It is also not yet stable (templates?
  9511. exceptions? multiple inheritance?)  It is also bigger, slower, and
  9512. harder to learn.  Some people even consider it as a failure because it
  9513. leaves most of C's unsafe features intact.
  9514.  
  9515. I like to see Python as a "democratic" language, available for all.
  9516. (That's why I distribute Mac and PC binaries -- most owners of those
  9517. machines don't have *any* compiler.)  Requiring people to acquire C++
  9518. before building Python is one more burden and will surely slow down
  9519. Python's acceptance.
  9520.  
  9521. But, feel free to prove me wrong...
  9522.  
  9523. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9524. 
  9525. 
  9526. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  9527.     id AA06500 (5.65b/3.8/CWI-Amsterdam); Sat, 19 Jun 1993 10:55:40 +0200
  9528. Received: by voorn.cwi.nl with SMTP
  9529.     id AA26409 (5.65b/3.8/CWI-Amsterdam); Sat, 19 Jun 1993 10:55:39 +0200
  9530. Message-Id: <9306190855.AA26409=guido@voorn.cwi.nl>
  9531. To: python-list@cwi.nl
  9532. Subject: Re: type casting and c++ 
  9533. In-Reply-To: Your message of "Sat, 19 Jun 1993 00:08:37 MDT."
  9534.              <93Jun19.000848edt.18552@gpu.utcc.utoronto.ca> 
  9535. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9536. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9537. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9538. Date: Sat, 19 Jun 1993 10:55:39 +0200
  9539. From: Guido van Rossum <Guido.van.Rossum@cwi.nl>
  9540.  
  9541. > This sounds like a good argument for translating Python into C++.
  9542. > Here's another: that business of explicitly managing reference counts
  9543. > could be greatly simplified using C++ constructors and destructors.
  9544. > This would make the job of writing extension modules less error prone.
  9545.  
  9546. I tried setting up a scheme for automatic reference counting C++ once
  9547. and soon found out that it incurs a lot more overhead than the way
  9548. it's done manually in C now.  The problem is that in many situations
  9549. you don't need to change a reference count because you don't
  9550. permanently store a copy of a pointer, you only "peek" at it.  A
  9551. simple-minded reference-counting pointer type in C++ won't know this
  9552. and will add referece count adjustments in many more places than
  9553. necessary.  When this happens at the lower levels it will really slow
  9554. things down.
  9555.  
  9556. > Ignore for a moment the fact that it would be a lot of work,
  9557. > and consider this: Python is written in C because C is ubiquitous.
  9558. > Since Python began, C++ has become much more widely available.
  9559. > There are now multiple PC and Mac compilers, and GNU seems to cover the
  9560. > Unix platforms.  Is C++ now sufficiently widely available that converting
  9561. > Python to C++ makes sense?
  9562.  
  9563. I have my doubts.  C++ is more widely available, but it is not by any
  9564. measure "ubiquitous".  It is also not yet stable (templates?
  9565. exceptions? multiple inheritance?)  It is also bigger, slower, and
  9566. harder to learn.  Some people even consider it as a failure because it
  9567. leaves most of C's unsafe features intact.
  9568.  
  9569. I like to see Python as a "democratic" language, available for all.
  9570. (That's why I distribute Mac and PC binaries -- most owners of those
  9571. machines don't have *any* compiler.)  Requiring people to acquire C++
  9572. before building Python is one more burden and will surely slow down
  9573. Python's acceptance.
  9574.  
  9575. But, feel free to prove me wrong...
  9576.  
  9577. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9578. 
  9579. 
  9580. Replied: Fri, 02 Jul 1993 12:43:15 +0200
  9581. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list"
  9582. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  9583.     id AA17074 (5.65b/3.8/CWI-Amsterdam); Fri, 2 Jul 1993 02:30:02 +0200
  9584. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  9585.     id AA18751; Thu, 1 Jul 93 17:31:04 -0700
  9586. Received: by eng2.sequent.com (5.65/1.34)
  9587.     id AA05618; Thu, 1 Jul 93 17:29:55 -0700
  9588. Message-Id: <9307020029.AA05618@eng2.sequent.com>
  9589. To: Python Mailing List <python-list@cwi.nl>
  9590. Subject: Did somebody implement a curses interface?
  9591. Priority: Normal
  9592. Precedence: first-class
  9593. Organization: Sequent Computer Systems, Inc.
  9594.           Service Technology - MailStop: WIL2-610
  9595.           15450 S.W. Koll Parkway
  9596.           Beaverton, OR  97006-6063
  9597. X-Phone: (503) 578-4404
  9598. X-Fax: (503) 578-4540
  9599. X-Uucp: ...!uunet!sequent!jaap
  9600. X-Internet: jaap@sequent.com
  9601. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  9602.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  9603.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  9604. Date: Thu, 01 Jul 93 17:29:54 PDT
  9605. From: Jaap Vermeulen <jaap@sequent.com>
  9606.  
  9607.  
  9608. Guess what, I could use a curses interface in Python.  There was some
  9609. traffic about a curses interface some time ago, but no definite
  9610. answer.  It looked like people were porting a curses interface or a
  9611. subset of it.  Is there a curses or curses-like module out there that I
  9612. could use?
  9613.  
  9614. Thanks,
  9615.  
  9616.     -Jaap-
  9617. --
  9618. Jaap Vermeulen                    +--------------------------+
  9619.                         | Sequent Computer Systems |
  9620.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  9621.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  9622. 
  9623. 
  9624. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  9625.     id AA17525 (5.65b/3.8/CWI-Amsterdam); Fri, 2 Jul 1993 02:54:00 +0200
  9626. From: Lance Ellinghouse <lance@markv.com>
  9627. X-Mailer: SCO System V Mail (version 3.2)
  9628. To: jaap@sequent.com
  9629. Subject: Re: Did somebody implement a curses interface?
  9630. Cc: python-list@cwi.nl
  9631. Date: Thu, 1 Jul 93 17:53:00 PDT
  9632. Message-Id:  <9307011753.aa26428@hermix.markv.com>
  9633.  
  9634.  
  9635. I am looking for a curses package also...
  9636. but noone has come up with one yet..
  9637. Maybe we can make it together??
  9638.  
  9639. Lance
  9640. lance@markv.com
  9641. 
  9642. 
  9643. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  9644.     id AA05870 (5.65b/3.8/CWI-Amsterdam); Fri, 2 Jul 1993 12:43:16 +0200
  9645. Received: by voorn.cwi.nl with SMTP
  9646.     id AA04061 (5.65b/3.8/CWI-Amsterdam); Fri, 2 Jul 1993 12:43:15 +0200
  9647. Message-Id: <9307021043.AA04061=guido@voorn.cwi.nl>
  9648. To: Jaap Vermeulen <jaap@sequent.com>
  9649. Cc: python-list@cwi.nl
  9650. Subject: Re: Did somebody implement a curses interface? 
  9651. In-Reply-To: Your message of "Thu, 01 Jul 1993 17:29:54 MDT."
  9652.              <9307020029.AA05618@eng2.sequent.com> 
  9653. From: Guido.van.Rossum@cwi.nl
  9654. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9655. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9656. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9657. Date: Fri, 02 Jul 1993 12:43:15 +0200
  9658. Sender: Guido.van.Rossum@cwi.nl
  9659.  
  9660. > Guess what, I could use a curses interface in Python.  There was some
  9661. > traffic about a curses interface some time ago, but no definite
  9662. > answer.  It looked like people were porting a curses interface or a
  9663. > subset of it.  Is there a curses or curses-like module out there that I
  9664. > could use?
  9665.  
  9666. I haven't heard of curses interfaces for Python -- I'm afraid most of
  9667. its users have bitmapped or or color graphics displays...
  9668.  
  9669. I suppose you could use the alfa version of STDWIN -- it's not exactly
  9670. curses but has similar functionality.  And guess what, your programs
  9671. will be portable to X11 as well!
  9672.  
  9673. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9674. 
  9675. 
  9676. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  9677.     id AA23720 (5.65b/3.8/CWI-Amsterdam); Sun, 4 Jul 1993 01:51:31 +0200
  9678. Received: by hermix.markv.com id ab28473; 3 Jul 93 16:51 PDT
  9679. From: Lance Ellinghouse <lance@markv.com>
  9680. X-Mailer: SCO System V Mail (version 3.2)
  9681. To: python-list@cwi.nl
  9682. Subject: setmember() 
  9683. Date: Sat, 3 Jul 93 16:39:25 PDT
  9684. Message-Id:  <9307031639.aa27852@hermix.markv.com>
  9685.  
  9686. Is there a reason that T_STRING types of memberlist elements
  9687. cause a "TypeError" to be raised?
  9688.  
  9689. I have an element that I NEED to be as T_STRING type, but setmember()
  9690. will not allow that. You can READ T_STRING types, but now WRITE to it..
  9691. I know there is a problem with the possibility of overwriting the end
  9692. of the buffer passed in, but this can be tested for..
  9693.  
  9694. Since there will ALWAYS going to be an element AFTER a T_STRING element,
  9695. we could have it look at the offset on the element AFTER the T_STRING
  9696. element and the subtract 1 and then that will give the length allowed.
  9697. If the string is longer than that length, then an exception could be
  9698. raised OR just truncate..
  9699.  
  9700. Comments??
  9701.  
  9702. Lance Ellinghouse
  9703. lance@markv.com
  9704.  
  9705. 
  9706. 
  9707. Replied: Sun, 04 Jul 1993 22:22:38 +0200
  9708. Replied: "Lance Ellinghouse <lance@markv.com> python-list"
  9709. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  9710.     id AA28005 (5.65b/3.8/CWI-Amsterdam); Sun, 4 Jul 1993 06:43:58 +0200
  9711. From: Lance Ellinghouse <lance@markv.com>
  9712. X-Mailer: SCO System V Mail (version 3.2)
  9713. To: Guido.van.Rossum@cwi.nl
  9714. Subject: fixes to structmember.c
  9715. Date: Sat, 3 Jul 93 21:43:23 PDT
  9716. Message-Id:  <9307032143.aa20925@hermix.markv.com>
  9717.  
  9718.  
  9719. Here are CVS diffs for a corrected version of structmember.c.
  9720. This fixes a couple bugs in the parsing routines for T_CHAR and 
  9721. puts the fix I sugested for T_STRING...
  9722.  
  9723. Lance Ellinghouse
  9724. lance@markv.com
  9725. ======
  9726. ===================================================================
  9727. RCS file: /u/lance/CVS/python/src/structmember.c,v
  9728. retrieving revision 1.1.1.1
  9729. diff -r1.1.1.1 structmember.c
  9730. 104c104
  9731. <                 if (*(char**)addr == NULL) {
  9732. ---
  9733. >                 if ((char*)addr == NULL) {
  9734. 109c109
  9735. <                     v = newstringobject(*(char**)addr);
  9736. ---
  9737. >                     v = newstringobject((char*)addr);
  9738. 143c143
  9739. <             if (l->readonly || l->type == T_STRING) {
  9740. ---
  9741. >             if (l->readonly) {
  9742. 148a149,163
  9743. >             case T_STRING:
  9744. >                 {
  9745. >                     int i, j;
  9746. >                     struct memberlist *g = l;
  9747. >                     if (!is_stringobject(v)) {
  9748. >                         err_badarg();
  9749. >                         return -1;
  9750. >                     }
  9751. >                     g++;
  9752. >                     i = g->offset;
  9753. >                     j = i - l->offset - 1;
  9754. >                     strncpy((char *)addr,getstringvalue(v),j);
  9755. >                     *(char *)(addr+j) = '\0';
  9756. >                     break;
  9757. >                 }
  9758. 224a240
  9759. >                 break;
  9760. 
  9761. 
  9762. To: Lance Ellinghouse <lance@markv.com>
  9763. cc: python-list
  9764. Subject: Re: fixes to structmember.c 
  9765. In-reply-to: Your message of "Sat, 03 Jul 1993 21:43:23 MDT."
  9766.              <9307032143.aa20925@hermix.markv.com> 
  9767. From: Guido.van.Rossum@cwi.nl
  9768. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9769. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9770. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9771. Date: Sun, 04 Jul 1993 22:22:39 +0200
  9772. Sender: guido
  9773.  
  9774. Lance writes:
  9775.  
  9776. > Is there a reason that T_STRING types of memberlist elements
  9777. > cause a "TypeError" to be raised?
  9778. > I have an element that I NEED to be as T_STRING type, but setmember()
  9779. > will not allow that. You can READ T_STRING types, but now WRITE to it..
  9780. > I know there is a problem with the possibility of overwriting the end
  9781. > of the buffer passed in, but this can be tested for..
  9782. > Since there will ALWAYS going to be an element AFTER a T_STRING element,
  9783. > we could have it look at the offset on the element AFTER the T_STRING
  9784. > element and the subtract 1 and then that will give the length allowed.
  9785. > If the string is longer than that length, then an exception could be
  9786. > raised OR just truncate..
  9787.  
  9788. The T_STRING member type is intended for struct members of type "char
  9789. *", not for struct members of type "char[]" as you seem to be implying
  9790. (the patch you sent me privately changes the meaning to "char[]"!)
  9791.  
  9792. My preferred solution would be to add a new type T_BUFFER which means
  9793. a member of type char[], with a way to specify the length explicitly.
  9794. (I don't like the idea of looking at the next element because theg
  9795. elements may not be listed in ascending order, and sometimes some
  9796. elements are not listed at all, e.g. when their type in inexpressible.)
  9797.  
  9798. For binary compatibility (important in the light of dynamically loaded
  9799. modules!), I would propose the following hack to store the length:
  9800. the type proper is only the lower 4 bits (this is just sufficient for
  9801. the current set of types), the length is in the upper 12 or 28 bits
  9802. (12 bits on machines where ints are 2 bytes, like some Mac or PC
  9803. compilers).  This lets you specify buffers of up to 4095 bytes if you
  9804. are careful.  (Alternatively, you could overload the readonly field --
  9805. if it is <= 0, the value is writable, if it is > 0, it is readonly.
  9806. This gives you 15 bits for the size.)
  9807.  
  9808. Note that Donald Beaudry has proposed (in private email) a much more
  9809. general mechanism which should take care of this and other
  9810. restrictions of the structmember.[ch] files.  However this would
  9811. require rewriting all code that currently uses structmember, and also
  9812. I believe Donald was still pondering ways to make his solution even
  9813. more general, so I'm not sure whether it will appear in the next
  9814. release...
  9815.  
  9816. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9817. 
  9818. 
  9819. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  9820.     id AA06129 (5.65b/3.8/CWI-Amsterdam); Sun, 4 Jul 1993 22:22:39 +0200
  9821. Received: by voorn.cwi.nl with SMTP
  9822.     id AA09075 (5.65b/3.8/CWI-Amsterdam); Sun, 4 Jul 1993 22:22:39 +0200
  9823. Message-Id: <9307042022.AA09075=guido@voorn.cwi.nl>
  9824. To: Lance Ellinghouse <lance@markv.com>
  9825. Cc: python-list@cwi.nl
  9826. Subject: Re: fixes to structmember.c 
  9827. In-Reply-To: Your message of "Sat, 03 Jul 1993 21:43:23 MDT."
  9828.              <9307032143.aa20925@hermix.markv.com> 
  9829. From: Guido.van.Rossum@cwi.nl
  9830. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  9831. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  9832. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9833. Date: Sun, 04 Jul 1993 22:22:39 +0200
  9834. Sender: Guido.van.Rossum@cwi.nl
  9835.  
  9836. Lance writes:
  9837.  
  9838. > Is there a reason that T_STRING types of memberlist elements
  9839. > cause a "TypeError" to be raised?
  9840. > I have an element that I NEED to be as T_STRING type, but setmember()
  9841. > will not allow that. You can READ T_STRING types, but now WRITE to it..
  9842. > I know there is a problem with the possibility of overwriting the end
  9843. > of the buffer passed in, but this can be tested for..
  9844. > Since there will ALWAYS going to be an element AFTER a T_STRING element,
  9845. > we could have it look at the offset on the element AFTER the T_STRING
  9846. > element and the subtract 1 and then that will give the length allowed.
  9847. > If the string is longer than that length, then an exception could be
  9848. > raised OR just truncate..
  9849.  
  9850. The T_STRING member type is intended for struct members of type "char
  9851. *", not for struct members of type "char[]" as you seem to be implying
  9852. (the patch you sent me privately changes the meaning to "char[]"!)
  9853.  
  9854. My preferred solution would be to add a new type T_BUFFER which means
  9855. a member of type char[], with a way to specify the length explicitly.
  9856. (I don't like the idea of looking at the next element because theg
  9857. elements may not be listed in ascending order, and sometimes some
  9858. elements are not listed at all, e.g. when their type in inexpressible.)
  9859.  
  9860. For binary compatibility (important in the light of dynamically loaded
  9861. modules!), I would propose the following hack to store the length:
  9862. the type proper is only the lower 4 bits (this is just sufficient for
  9863. the current set of types), the length is in the upper 12 or 28 bits
  9864. (12 bits on machines where ints are 2 bytes, like some Mac or PC
  9865. compilers).  This lets you specify buffers of up to 4095 bytes if you
  9866. are careful.  (Alternatively, you could overload the readonly field --
  9867. if it is <= 0, the value is writable, if it is > 0, it is readonly.
  9868. This gives you 15 bits for the size.)
  9869.  
  9870. Note that Donald Beaudry has proposed (in private email) a much more
  9871. general mechanism which should take care of this and other
  9872. restrictions of the structmember.[ch] files.  However this would
  9873. require rewriting all code that currently uses structmember, and also
  9874. I believe Donald was still pondering ways to make his solution even
  9875. more general, so I'm not sure whether it will appear in the next
  9876. release...
  9877.  
  9878. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  9879. 
  9880. 
  9881. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  9882.     id AA10873 (5.65b/3.8/CWI-Amsterdam); Mon, 5 Jul 1993 00:20:59 +0200
  9883. Received: by voorn.cwi.nl with SMTP
  9884.     id AA09207 (5.65b/3.8/CWI-Amsterdam); Mon, 5 Jul 1993 00:20:58 +0200
  9885. Message-Id: <9307042220.AA09207=guido@voorn.cwi.nl>
  9886. To: python-list@cwi.nl
  9887. Subject: THE GREAT RENAMING -- SECOND DRAFT
  9888. From: Guido.van.Rossum@cwi.nl
  9889. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  9890. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  9891. Date: Mon, 05 Jul 1993 00:20:57 +0200
  9892. Sender: Guido.van.Rossum@cwi.nl
  9893.  
  9894. I know you thought I'd forgotten about it, but no, I was just busy
  9895. with other things (as well as a little bored with the long list of new
  9896. names to invent...).
  9897.  
  9898. Here's the result of my workon the matter, in two parts: (1) a
  9899. modified version of the naming conventions proposal; (2) a list giving
  9900. new names for almost all "global" (in some sense) names in the current
  9901. interpreter.  This is not cast in concrete, so don't use this yet, but
  9902. read it through if you have time, and let me know where the weak spots
  9903. are.
  9904.  
  9905.     --Guido
  9906.  
  9907. ========================================================================
  9908. [Change bars indicate changes with respect to the first draft.]
  9909.  
  9910. | Naming Conventions -- Second Draft Proposal
  9911. | *******************************************
  9912.   
  9913.   It is quite easy to extend Python with a new module written in C.  It
  9914.   should be equally easy to embed the Python interpreter as a library in
  9915.   an existing (or new) application.  This is indeed possible, but there
  9916.   is a potential problem when the application is large: the Python
  9917.   interpreter library defines many external names that may clash with
  9918.   names defined by the application.  To a lesser extend the macros,
  9919. | structures and typedefs defined in Python's public header files may
  9920.   also clash with application-defined names (or with names defined by
  9921.   other libraries, when the application needs to use several libraries
  9922.   in one file).
  9923.   
  9924.   This article proposes a change to the naming of all external
  9925.   functions, macros, structures, typedefs etc. that are in any way
  9926.   visible to the application with the intent to make clashes avoidable.
  9927.   (This excludes the names of static functions and variables, local
  9928.   variables, structure members, and macros, structures and typedefs
  9929. | defined in .c files or .h files for internal use only.)  At the same
  9930.   time the set of names is somewhat rationalized to make it easier to
  9931.   guess where a name is defined.
  9932.   
  9933.   The purpose of this proposal is to get feedback.  This is your chance
  9934.   to make your voice heard!  Please evaluate every aspect of the
  9935.   proposal and let me know whether you like it or not.  No effort has
  9936.   yet begun to implement the proposal, so there are no big costs
  9937.   involved in changes to the proposal.  Your opinion is especially
  9938.   important if you have written (or are maintaining) code that extends
  9939.   the Python interpreter, since you will have to change your code and
  9940.   learn to use the new conventions.
  9941.  
  9942. | This is the second draft; the next version will be implemented,
  9943. | so this is your last chance to make your voice heard.
  9944.   
  9945.   Note that these changes affect the C code that implements the Python
  9946.   interpreter (and its extensions) only; the Python language as seen by
  9947.   Python programmers will remain unchanged!
  9948.   
  9949.   
  9950.   Basic Conventions
  9951.   =================
  9952.   
  9953.   The mechanism to avoid clashes is to prefix all relevant names with
  9954.   the string Py.  This gives an application a very simple way to avoid
  9955.   clashes: simply don't define names starting with Py in the
  9956.   application.  A similar mechanism is successfully used by most
  9957.   widespread libraries, e.g. X.
  9958.   
  9959.   The full naming scheme gives functions a name as follows:
  9960. | [_]Py<Module>_<Function>, where <Module> is the (sometimes abbreviated)
  9961.   name of the module to which the function belongs (this may also be a
  9962.   basic type), and <Function> is a descriptive name for the function.
  9963. | [_] stands for an optional underscore (for internal functions).
  9964.   The <Module> and <Function> parts use a mixed-case convention: each
  9965.   is spelled with an initial capital letter, and if they consist of
  9966.   multiple words each word has an initial capital.  Embedded underscores
  9967.   are not used except between <Module> and <Function>.  Some examples:
  9968.   
  9969. | PyObject_Print
  9970.   PyList_Append
  9971.   PyList_GetItem
  9972. | PyList_Alloc
  9973. | PyString_AsString
  9974.   PyErr_SetString
  9975.   
  9976. | Some utility functions have a prefix of just Py_, e.g.
  9977.   
  9978. |
  9979. | Py_FatalError
  9980.   Py_MakeValue
  9981.   
  9982.   Global variables are named using similar conventions, e.g.
  9983.   
  9984.   PyList_Type
  9985.   PyExc_ZeroDivisionError
  9986.   
  9987. |  Names that have to be global for some reason but are
  9988.   not part of the official interface have an initial underscore, e.g.
  9989.   
  9990.   _Py_RefTotal
  9991. | _PyObject_New
  9992.   
  9993. | Macros that behave like functions are named like functions, e.g.:
  9994.   
  9995. | PyList_Valid
  9996. | _Py_NewReference
  9997.   
  9998. | Macros used as symbolic constants and enum values have a second part that
  9999.   is entirely in capitals and uses underscores to separate words.  So
  10000.   do enums.  E.g.:
  10001.   
  10002.   Py_PRINT_RAW
  10003.  
  10004. | Macros that are not completely like functions (e.g. have a
  10005. | typedef as argument or may evaluate one or more arguments several
  10006. | times, or unsafe inline versions) also follow this convention, e.g.:
  10007. |
  10008. | Py_INCREF
  10009. | PyFloat_AS_DOUBLE
  10010.   
  10011.   Typedefs contain no underscore; they consist of Py followed by one or
  10012.   more words with initial capitals, e.g.:
  10013.   
  10014.   PyObject
  10015.   PyListObject
  10016. |  PyNumberMethods
  10017.   
  10018.   Most of these typedef names correspond to structures; the structure
  10019.   tag will be the typedef name prefixed with an underdscore.
  10020.   
  10021.   Note that the current system has a number of structures that are not
  10022.   covered by typedefs.  These will be given typedef names.
  10023. | For example:
  10024. |
  10025. | PyMemberDef
  10026. | PyMethodDef
  10027.   
  10028.   Also note that pointer types will continue to be written with the "*"
  10029.   notation, e.g. "PyObject *".  Pointers in C have sufficiently special
  10030.   semantics to make it important in practice to know whether a
  10031.   particular variable is a pointer; e.g. Python frequently uses casts
  10032.   between various object pointers.
  10033.  
  10034. | Typedefs do not end in "_t".  I find this ugly and unnecessary.
  10035.   
  10036. | For now, header file names will remain unchanged.  In the future,
  10037. | header files may be renamed to <Py/List.h> etc., with <Py/Python.h>
  10038. | a convenience header like the current "allobjects.h".  (There was
  10039. | considerable diversity in the suggestions for a new directory
  10040. | structure, so for now I'll leave it unchanged until I have thought
  10041. | about it more.)
  10042.  
  10043. | Header files will be protected against multiple inclusion with a
  10044. | macro and an #ifdef, as follows:
  10045. |
  10046. | #ifndef PyFOO_H
  10047. | #define PyFOO_H
  10048. | .
  10049. | . (entire contents of file goes here)
  10050. | .
  10051. | #endif /* PyFOO_H */
  10052.   
  10053.   
  10054.   Transition Period
  10055.   =================
  10056.   
  10057.   During a transition period, which will last at least two releases that
  10058.   each live at least 3 months (giving a total of at least 6 months), it
  10059.   will be possible to use the old names and the new names together.
  10060.   The transition mechanism uses #define to identify the new and old names.
  10061.   
  10062.   In the first transition release, the (majority of) source code will
  10063.   still use the old names, including the old header file names, but
  10064.   macros will be defined to support the use of the new names, e.g.:
  10065.   
  10066.   #define PyObject object
  10067.   
  10068.   In the second transition release, the source code will use the new
  10069.   names, also for header file names, and macros will be defined to
  10070.   support code that still uses the old names, e.g.:
  10071.   
  10072.   #define object PyObject
  10073.   
  10074. | Header file names may be changed in the second transition release
  10075. | (if I can agree with myself on a good naming scheme).
  10076.   
  10077.   In both transition releases, the compatibility macros will be gathered
  10078.   in a single header file (a different one each time!).
  10079.   
  10080.   A Python script will be provided which translates C code from the old
  10081.   to the new naming conventions with 99% accuracy.  It remains to be
  10082.   seen whether occurrences in comments should be replaced; when comments
  10083.   refer to functions and typedefs etc., they should, but some names
  10084.   (e.g. object!) can also be used as a noun, so global substitutions may
  10085.   cause undesired effects.  Also, there are some situations where names
  10086.   occurring in strings must be substituted!
  10087.   
  10088. | (the sections on other changes and an alternate proposal have been
  10089. | deleted)
  10090.  
  10091. ========================================================================
  10092.  
  10093. # This file contains an almost complete list of identifiers that will
  10094. # change at the Great Renaming.  The rules are explained in the file
  10095. # NAMING; this file just contains a list of mappings.  With few
  10096. # exceptions, this file can be used as input for a renaming script that
  10097. # I have devised (which assumes its input lines contain pairs of old
  10098. # name and new name after comment stripping).  Note that names which
  10099. # are global by mistake in the current  are not listed here; they will
  10100. # be made static (manually).  There may also be some names here that
  10101. # are not defined in the 0.9.8 release; these have been introduced in
  10102. # the code after that release.  I've attempted to remove most of these
  10103. # but sometimes I may not have remembered their status correctly...
  10104.  
  10105.  
  10106. # ====== CPP symbols used to switch on ======
  10107.  
  10108. NDEBUG            Py_NO_DEBUG
  10109. TRACE_REFS        Py_TRACE_REFS
  10110. REF_DEBUG        Py_REF_DEBUG
  10111. USE_...            Py_USE_...
  10112. HAVE_PROTOTYPES        Py_HAVE_PROTOTYPES
  10113. HAVE_STDLIB        Py_HAVE_STDLIB
  10114.  
  10115. # Each .h file "foo.h" will be protected by a macro and ifdef as follows:
  10116. # #ifndef PyFOO_H
  10117. # #define PyFOO_H
  10118. # .
  10119. # . (entire contents of file goes here)
  10120. # .
  10121. # #endif /* PyFOO_H */
  10122.  
  10123.  
  10124. # ====== Data ======
  10125.  
  10126. # --- Misc global data ---
  10127.  
  10128. FalseObject        _Py_ZeroStruct
  10129. NoObject        _Py_NoneStruct
  10130. TrueObject        _Py_TrueStruct
  10131. debugging        Py_DebugFlag
  10132. gram            _PyParser_Grammar
  10133. sys_profile        _PySys_ProfileFunc
  10134. sys_trace        _PySys_TraceFunc
  10135. threads_started        _PyThread_Started
  10136. tok_name        _PyParser_TokenNames
  10137. verbose            Py_VerboseFlag
  10138.  
  10139. # --- Built-in exceptions ---
  10140.  
  10141. AttributeError        PyExc_AttributeError
  10142. EOFError        PyExc_EOFError
  10143. IOError            PyExc_IOError
  10144. ImportError        PyExc_ImportError
  10145. IndexError        PyExc_IndexError
  10146. KeyError        PyExc_KeyError
  10147. MemoryError        PyExc_MemoryError
  10148. NameError        PyExc_NameError
  10149. OverflowError        PyExc_OverflowError
  10150. RuntimeError        PyExc_RuntimeError
  10151. SyntaxError        PyExc_SyntaxError
  10152. SystemError        PyExc_SystemError
  10153. TypeError        PyExc_TypeError
  10154. ValueError        PyExc_ValueError
  10155. ZeroDivisionError    PyExc_ZeroDivisionError
  10156. KeyboardInterrupt    PyExc_KeyboardInterrupt
  10157. SystemExit        PyExc_SystemExit
  10158.  
  10159. # --- Built-in type objects --- (only used through is_<type>object() macros)
  10160.  
  10161. # Atomic basic types
  10162. Floattype        PyFloat_Type
  10163. Inttype            PyInt_Type
  10164. Longtype        PyLong_Type
  10165. Notype            PyNothing_Type
  10166. Stringtype        PyString_Type        # Also composite (sequence)
  10167. Typetype        PyType_Type
  10168.  
  10169. # Composite basic types
  10170. Listtype        PyList_Type
  10171. Dicttype        PyDict_Type
  10172. Tupletype        PyTuple_Type
  10173.  
  10174. # I/O types
  10175. Filetype        PyFile_Type
  10176.  
  10177. # Interpreter related types
  10178. Classtype        PyClass_Type
  10179. Functype        PyFunction_Type
  10180. Instancemethodtype    PyMethod_Type
  10181. Instancetype        PyInstance_Type
  10182. Methodtype        PyCFunction_Type    # Split in CMethod, CFunction?
  10183. Moduletype        PyModule_Type
  10184.  
  10185. # Interpreter internal types
  10186. Codetype        PyCode_Type
  10187. Frametype        PyFrame_Type
  10188.  
  10189.  
  10190. # ====== Typedefs ======
  10191.  
  10192. *object            PyObject
  10193. #varobject        no longer visible for users
  10194.  
  10195. floatobject        PyFloatObject
  10196. intobject        PyIntObject
  10197. longobject        PyLongObject
  10198. noobject        PyNothingObject
  10199. stringobject        PyStringObject
  10200. typeobject        PyTypeObject
  10201.  
  10202. listobject        PyListObject
  10203. dictobject        PyDictObject
  10204. tupleobject        PyTupleObject
  10205.  
  10206. fileobject        PyFileObject
  10207.  
  10208. classobject        PyClassObject
  10209. codeobject        PyCodeObject
  10210. frameobject        PyFrameObject
  10211. funcobject        PyFunctionObject
  10212. instancemethodobject    PyMethodObject
  10213. instanceobject        PyInstanceObject
  10214. methodobject        PyCFunctionObject    # Split in CMethod, CFunction?
  10215. moduleobject        PyModuleObject
  10216.  
  10217. number_methods        PyNumberMethods
  10218. sequence_methods    PySequenceMethods
  10219. mapping_methods        PyMappingMethods
  10220.  
  10221.  
  10222. # ====== Funny CPP macros ======
  10223.  
  10224. OB_HEAD            PyObject_HEAD
  10225. OB_VARHEAD        PyObject_VAR_HEAD
  10226. OB_HEAD_INIT        PyObject_HEAD_INIT
  10227.  
  10228. NEWOBJ            PyObject_NEW
  10229. NEWVAROBJ        PyObject_NEW_VAR
  10230.  
  10231. PROTO            Py_PROTO
  10232. PROTO            Py_FPROTO
  10233.  
  10234. # For ANY* I break my own rule of not defining names for pointer
  10235. # types, since here it is essential that the pointer not be
  10236. # dereferenced!
  10237. # (My script doesn't understand this, I'll fix it manually)
  10238. ANY*            PyUnivPtr    # either char* or void*
  10239.  
  10240. NEW            PyMem_NEW
  10241. RESIZE            PyMem_RESIZE
  10242. DEL            PyMem_DEL
  10243. XDEL            PyMem_XDEL
  10244. MALLARG            size_t        # this macro is no longer needed
  10245.  
  10246. BGN_SAVE        Py_BEGIN_ALLOW_THREADS
  10247. RET_SAVE        Py_BLOCK_THREADS
  10248. RES_SAVE        Py_UNBLOCK_THREADS
  10249. END_SAVE        Py_END_ALLOW_THREADS
  10250.  
  10251.  
  10252. # ====== Enumerated Values ======
  10253.  
  10254. # E_OK, etc.: unchanged (used internally only)
  10255.  
  10256. # T_INT, etc.: for now, these remain the same; in the future
  10257. # structmember.h will be replaced by a more powerful (extensible)
  10258. # module where types are expressed by strings.
  10259.  
  10260.  
  10261. # ====== Structure tags ======
  10262. # Avoid completely (use forward typedefs instead)
  10263.  
  10264. # (My script can't handle those, wil lfix manually)
  10265. #struct memberlist    PyMemberDef
  10266. #struct methodlist    PyMethodDef
  10267. #(etc.)
  10268.  
  10269.  
  10270. # ====== Type tests ======
  10271.  
  10272. is_floatobject        PyFloat_Check
  10273. is_intobject        PyInt_Check
  10274. is_longobject        PyLong_Check
  10275. is_noobject        PyNothing_Check
  10276. is_stringobject        PyString_Check
  10277. is_typeobject        PyType_Check
  10278.  
  10279. is_listobject        PyList_Check
  10280. is_dictobject        PyDict_Check
  10281. is_tupleobject        PyTuple_Check
  10282.  
  10283. is_fileobject        PyFile_Check
  10284.  
  10285. is_classobject        PyClass_Check
  10286. is_codeobject        PyCode_Check
  10287. is_frameobject        PyFrame_Check
  10288. is_funcobject        PyFunction_Check
  10289. is_instancemethodobject    PyMethod_Check
  10290. is_instanceobject    PyInstance_Check
  10291. is_methodobject        PyCFunction_Check    # Split in CMethod, CFunction?
  10292. is_moduleobject        PyModule_Check
  10293.  
  10294.  
  10295. # Operations on built-in types
  10296.  
  10297. # --- Generic Object Operations ---
  10298.  
  10299. INCREF            Py_INCREF        # uses arg multiple times
  10300. DECREF            Py_DECREF        # " " " "
  10301. XINCREF            Py_XINCREF
  10302. XDECREF            Py_XDECREF
  10303.  
  10304. NEWREF            _Py_NewReference
  10305. DELREF            _Py_Dealloc
  10306. UNREF            _Py_ForgetReference
  10307.  
  10308. None            Py_None
  10309. False            Py_False
  10310. True            Py_True
  10311.  
  10312. cmpobject        PyObject_Compare
  10313. getattr            PyObject_GetAttrString
  10314. getattro        PyObject_GetAttr
  10315. hashobject        PyObject_Hash
  10316. newobject        _PyObject_New
  10317. newvarobject        _PyObject_NewVar
  10318. printobject        PyObject_Print
  10319. reprobject        PyObject_Repr
  10320. setattr            PyObject_SetAttrString
  10321. setattro        PyObject_SetAttr
  10322. testbool        PyObject_IsTrue
  10323.  
  10324. # --- flags for PyObject_Print ---
  10325.  
  10326. PRINT_RAW        Py_PRINT_RAW
  10327.  
  10328. # --- Atomic basic objects ---
  10329.  
  10330. float_buf_repr        PyFloat_AsString    # need to reverse arguments
  10331. getfloatvalue        PyFloat_AsDouble
  10332. GETFLOATVALUE        PyFloat_AS_DOUBLE
  10333. newfloatobject        PyFloat_FromDouble
  10334.  
  10335. getintvalue        PyInt_AsLong
  10336. GETINTVALUE        PyInt_AS_LONG
  10337. newintobject        PyInt_FromLong
  10338.  
  10339. alloclongobject        _PyLong_New        # used by marshal, mpz
  10340. dgetlongvalue        PyLong_AsDouble
  10341. dnewlongobject        PyLong_FromDouble
  10342. getlongvalue        PyLong_AsLong
  10343. long_scan        PyLong_FromString
  10344. newlongobject        PyLong_FromLong
  10345.  
  10346. formatstring        PyString_Format
  10347. getstringsize        PyString_Size
  10348. getstringvalue        PyString_AsString
  10349. GETSTRINGVALUE        PyString_AS_STRING
  10350. joinstring        PyString_Concat
  10351. newsizedstringobject    PyString_FromStringAndSize
  10352. newstringobject        PyString_FromString
  10353. resizestring        _PyString_Resize
  10354.  
  10355. # --- Composite basic objects ---
  10356.  
  10357. addlistitem        PyList_Append
  10358. getlistitem        PyList_GetItem
  10359. GETLISTITEM        PyList_GET_ITEM
  10360. getlistsize        PyList_Size
  10361. getlistslice        PyList_GetSlice
  10362. inslistitem        PyList_Insert
  10363. newlistobject        PyList_New
  10364. setlistitem        PyList_SetItem
  10365. setlistslice        PyList_SetSlice
  10366. sortlist        PyList_Sort
  10367.  
  10368. # These are different from the 0.9.8 distribution!  Hope you get the gist.
  10369. dictinsert        PyDict_SetItemString
  10370. dictlookup        PyDict_GetItemString
  10371. dictremove        PyDict_DelItemString
  10372. getmappingitems        PyDict_Items
  10373. getmappingkeys        PyDict_Keys
  10374. getmappingvalues    PyDict_Values
  10375. mappingclear        PyDict_Clear
  10376. mappinggetnext        PyDict_Next
  10377. mappinginsert        PyDict_SetItem
  10378. mappinglookup        PyDict_GetItem
  10379. mappingremove        PyDict_DelItem
  10380. newmappingobject    PyDict_New
  10381.  
  10382. gettupleitem        PyTuple_GetItem
  10383. GETTUPLEITEM        PyTuple_GET_ITEM
  10384. gettuplesize        PyTuple_Size
  10385. gettupleslice        PyTuple_GetSlice
  10386. newtupleobject        PyTuple_New
  10387. settupleitem        PyTuple_SetItem
  10388.  
  10389. # --- I/O Objects ---
  10390.  
  10391. filegetline        PyFile_GetLine
  10392. getfilefile        PyFile_AsFile
  10393. newfileobject        PyFile_FromString
  10394. newopenfileobject    PyFile_FromFile
  10395. softspace        PyFile_SoftSpace
  10396. writeobject        PyFile_WriteObject
  10397. writestring        PyFile_WriteString
  10398.  
  10399. # --- Interpreter Related Objects ---
  10400.  
  10401. # These are really all internal
  10402.  
  10403. instancemethodgetclass    PyMethod_Class
  10404. instancemethodgetfunc    PyMethod_Function
  10405. instancemethodgetself    PyMethod_Self
  10406. issubclass        PyClass_IsSubclass
  10407. newclassobject        PyClass_New
  10408. newinstancemethodobject    PyMethod_New
  10409. newinstanceobject    PyInstance_New
  10410.  
  10411. block            PyTryBlock
  10412.  
  10413. extend_stack        PyFrame_ExtendStack
  10414. newframeobject        PyFrame_New
  10415. pop_block        PyFrame_BlockPop
  10416. setup_block        PyFrame_BlockSetup
  10417.  
  10418. getfunccode        PyFunction_GetCode
  10419. getfuncglobals        PyFunction_GetGlobals
  10420. newfuncobject        PyFunction_New
  10421.  
  10422. method            PyCFunction
  10423.  
  10424. findmethod        Py_FindMethod    # Will be replaced by another mechanism
  10425. getmethod        PyCFunction_GetFunction
  10426. getself            PyCFunction_GetSelf
  10427. getvarargs        PyCFunction_IsVarArgs
  10428. newmethodobject        PyCFunction_New
  10429.  
  10430. getmoduledict        PyModule_GetDict
  10431. getmodulename        PyModule_GetName
  10432. newmoduleobject        PyModule_New
  10433.  
  10434.  
  10435. # ====== Text ======
  10436.  
  10437. # --- Parser and tokenizer --- (knows about tokens and grammar)
  10438.  
  10439. addaccelerators            PyGrammar_AddAccelerators
  10440.  
  10441. finddfa                PyGrammar_FindDFA
  10442. labelrepr            PyGrammar_LabelRepr
  10443.  
  10444. listtree            PyNode_ListTree
  10445.  
  10446. addchild            PyNode_AddChild
  10447. freetree            PyNode_Free
  10448. newtree                PyNode_New
  10449.  
  10450. addtoken            PyParser_AddToken
  10451. delparser            PyParser_Delete
  10452. newparser            PyParser_New
  10453.  
  10454. parsefile            PyParser_ParseFile
  10455. parsestring            PyParser_ParseString
  10456.  
  10457. tok_1char            PyToken_OneChar
  10458. tok_2char            PyToken_TwoChars
  10459. tok_free            PyTokenizer_Free
  10460. tok_get                PyTokenizer_Get
  10461. tok_setupf            PyTokenizer_FromFile
  10462. tok_setups            PyTokenizer_FromString
  10463.  
  10464.  
  10465. # --- Compiler --- (knows about grammar and objects and opcodes)
  10466.  
  10467. compile                PyNode_Compile
  10468. newcodeobject            PyCode_New
  10469.  
  10470.  
  10471. # --- Interpreter --- (knows about objects and opcodes)
  10472.  
  10473. call_object            PyEval_CallObject
  10474. eval_code            PyEval_EvalCode
  10475. flushline            Py_FlushLine
  10476. getglobals            PyEval_GetGlobals
  10477. getlocals            PyEval_GetLocals
  10478. init_save_thread        PyEval_InitThreads
  10479. printtraceback            PyErr_PrintTraceBack
  10480. restore_thread            PyEval_RestoreThread
  10481. save_thread            PyEval_SaveThread
  10482.  
  10483.  
  10484. # --- Interpreter support ---
  10485.  
  10486. tb_fetch            PyTraceBack_Fetch
  10487. tb_here                PyTraceBack_Here
  10488. tb_print            PyTraceBack_Print
  10489. tb_store            PyTraceBack_Store
  10490.  
  10491. add_module            PyImport_AddModule
  10492. doneimport            PyImport_Cleanup
  10493. get_modules            PyImport_GetModuleDict
  10494. import_module            PyImport_ImportModule
  10495. init_frozen            PyImport_ImportFrozenModule
  10496. initimport            PyImport_Init
  10497. reload_module            PyImport_ReloadModule
  10498.  
  10499. coerce                PyNumber_Coerce
  10500. getbuiltin            PyBuiltin_GetObject
  10501. initbuiltin            PyBuiltin_Init
  10502.  
  10503. initmarshal            PyMarshal_Init
  10504. rd_long                PyMarshal_ReadLongFromFile
  10505. rd_object            PyMarshal_ReadObjectFromFile
  10506. rds_object            PyMarshal_ReadObjectFromString
  10507. wr_long                PyMarshal_WriteLongToFile
  10508. wr_object            PyMarshal_WriteObjectToFile
  10509.  
  10510. initsys                PySys_Init
  10511. setpythonargv            PySys_SetArgv
  10512. setpythonpath            PySys_SetPath
  10513. sysget                PySys_GetObject
  10514. sysgetfile            PySys_GetFile
  10515. sysset                PySys_SetObject
  10516.  
  10517.  
  10518. # --- Embedding support ---
  10519.  
  10520. compile_string            Py_CompileString
  10521. fatal                Py_FatalError
  10522. goaway                Py_Exit
  10523. initall                Py_Initialize
  10524. print_error            PyErr_Print
  10525. parse_file            PyParser_SimpleParseFile
  10526. parse_string            PyParser_SimpleParseString
  10527. run                PyRun_AnyFile
  10528. run_script            PyRun_SimpleFile
  10529. run_command            PyRun_SimpleString
  10530. run_file            PyRun_File
  10531. run_string            PyRun_String
  10532. run_tty_1            PyRun_InteractiveOne
  10533. run_tty_loop            PyRun_InteractiveLoop
  10534.  
  10535. # --- Extension support ---
  10536.  
  10537. getmember        PyMember_Get
  10538. setmember        PyMember_Set
  10539.  
  10540. initmodule        Py_InitModule
  10541.  
  10542. mkvalue            Py_BuildValue
  10543. vmkvalue        Py_VaBuildValue
  10544.  
  10545. # --- Get arguments ---
  10546.  
  10547. getargs            PyArg_Parse
  10548. # getlonglistarg    # unused -- will disappear
  10549. # getlongtuplearg    # unused -- will disappear
  10550. # getshortlistarg    # unused -- will disappear
  10551. # getshorttuplearg    # unused -- will disappear
  10552.  
  10553. # --- Special set used by code generated by cgen.py (i.e. glmodule.c) ---
  10554.  
  10555. getichararg        PyArg_GetChar
  10556. getidoublearray        PyArg_GetDoubleArray
  10557. getifloatarg        PyArg_GetFloat
  10558. getifloatarray        PyArg_GetFloatArray
  10559. getilongarg        PyArg_GetLong
  10560. getilongarray        PyArg_GetLongArray
  10561. getilongarraysize    PyArg_GetLongArraySize
  10562. getiobjectarg        PyArg_GetObject
  10563. getishortarg        PyArg_GetShort
  10564. getishortarray        PyArg_GetShortArray
  10565. getishortarraysize    PyArg_GetShortArraySize
  10566. getistringarg        PyArg_GetString
  10567. # mknewcharobject (replaced by mkvalue("c", ...))
  10568.  
  10569. # --- Error handling ---
  10570. # (The 'Set' versions have an argument giving the exception type,
  10571. # the others don't)
  10572.  
  10573. err_badarg        PyErr_BadArgument
  10574. err_badcall        PyErr_BadInternalCall
  10575. err_input        PyErr_Input
  10576. err_nomem        PyErr_NoMemory
  10577. err_errno        PyErr_SetFromErrno
  10578. err_set            PyErr_SetNone
  10579. err_setstr        PyErr_SetString
  10580. err_setval        PyErr_SetObject
  10581. err_occurred        PyErr_Occurred
  10582. err_get            PyErr_GetAndClear
  10583. err_clear        PyErr_Clear
  10584.  
  10585.  
  10586. # --- Operating system dependent code ---
  10587.  
  10588. fgets_intr        PyOS_InterruptableGetString
  10589. initintr        PyOS_InitInterrupts
  10590. intrcheck        PyOS_InterruptOccurred
  10591. getmtime        PyOS_GetLastModificationTime
  10592.  
  10593. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  10594. 
  10595. 
  10596. Replied: Wed, 07 Jul 1993 10:13:05 +0200
  10597. Replied: "Bill McKinnon <mckinnon@ctron.com> "
  10598. Received: from nic.near.net by charon.cwi.nl with SMTP
  10599.     id AA11121 (5.65b/3.8/CWI-Amsterdam); Tue, 6 Jul 1993 23:02:20 +0200
  10600. Received: from ctron.com by nic.near.net id aa24063; 6 Jul 93 17:02 EDT
  10601. Received: from stealth.ctron.com ([134.141.6.107]) by ctron.com (4.1/SMI-4.1)
  10602.     id AA01511; Tue, 6 Jul 93 17:02:04 EDT
  10603. Received: from express.ctron by stealth.ctron.com (4.1/SMI-4.1)
  10604.     id AA19548; Tue, 6 Jul 93 17:01:53 EDT
  10605. Received: from pinto.ctron by express.ctron (4.1/SMI-4.1)
  10606.     id AA26376; Tue, 6 Jul 93 17:00:24 EDT
  10607. Date: Tue, 6 Jul 93 17:00:24 EDT
  10608. From: Bill McKinnon <mckinnon@ctron.com>
  10609. Message-Id: <9307062100.AA26376@express.ctron>
  10610. To: python-list@cwi.nl
  10611. Subject: commercial users?
  10612.  
  10613. We are currently looking at Python.  It would be used as an embedded
  10614. interpreter in a product.  The product would require "non-programmers"
  10615. to write Python.  I am looking for opinions about Pythons ease-of-use.
  10616. Any commercial success stories would also be helpful.
  10617. Thanks in advance.
  10618. Bill McKinnon
  10619. 
  10620. 
  10621. Replied: Thu, 08 Jul 1993 18:27:52 +0200
  10622. Replied: "python-list@cwi.nl "
  10623. Replied: Thu, 08 Jul 1993 13:07:50 +0200
  10624. Replied: "Jaap Vermeulen <jaap@sequent.com> "
  10625. Replied: Thu, 08 Jul 1993 10:31:47 +0200
  10626. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list@cwi.nl"
  10627. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  10628.     id AA11241 (5.65b/3.8/CWI-Amsterdam); Wed, 7 Jul 1993 23:46:05 +0200
  10629. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  10630.     id AA03562; Wed, 7 Jul 93 14:46:54 -0700
  10631. Received: by eng2.sequent.com (5.65/1.34)
  10632.     id AA14590; Wed, 7 Jul 93 14:45:53 -0700
  10633. Message-Id: <9307072145.AA14590@eng2.sequent.com>
  10634. To: python-list@cwi.nl
  10635. Subject: strop module and whitespace
  10636. Priority: Normal
  10637. Precedence: first-class
  10638. Organization: Sequent Computer Systems, Inc.
  10639.           Service Technology - MailStop: WIL2-610
  10640.           15450 S.W. Koll Parkway
  10641.           Beaverton, OR  97006-6063
  10642. X-Phone: (503) 578-4404
  10643. X-Fax: (503) 578-4540
  10644. X-Uucp: ...!uunet!sequent!jaap
  10645. X-Internet: jaap@sequent.com
  10646. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  10647.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  10648.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  10649. Date: Wed, 07 Jul 93 14:45:52 PDT
  10650. From: Jaap Vermeulen <jaap@sequent.com>
  10651.  
  10652.  
  10653. I have two questions:
  10654.  
  10655. 1) why is \r not considered whitespace?
  10656. 2) even if I fix whitespace in string.py, it is not being picked up
  10657.    because it has been hardcoded in module strop to be space, \t and
  10658.    \n. (string.py imports strop.)
  10659.  
  10660. Thanks,
  10661.  
  10662.     -Jaap-
  10663. --
  10664. Jaap Vermeulen                    +--------------------------+
  10665.                         | Sequent Computer Systems |
  10666.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  10667.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  10668. 
  10669. 
  10670. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  10671.     id AA04329 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 10:31:49 +0200
  10672. Received: by voorn.cwi.nl with SMTP
  10673.     id AA05505 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 10:31:48 +0200
  10674. Message-Id: <9307080831.AA05505=guido@voorn.cwi.nl>
  10675. To: Jaap Vermeulen <jaap@sequent.com>
  10676. Cc: python-list@cwi.nl
  10677. Subject: Re: strop module and whitespace 
  10678. In-Reply-To: Your message of "Wed, 07 Jul 1993 14:45:52 MDT."
  10679.              <9307072145.AA14590@eng2.sequent.com> 
  10680. From: Guido.van.Rossum@cwi.nl
  10681. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  10682. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  10683. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  10684. Date: Thu, 08 Jul 1993 10:31:47 +0200
  10685. Sender: Guido.van.Rossum@cwi.nl
  10686.  
  10687. > 1) why is \r not considered whitespace?
  10688.  
  10689. Perhaps because \r is really a arbitrary control character (Python
  10690. uses UNIX' convention that \n is the line separator).  Or perhaps it's
  10691. an oversight.  What set of characters does ANSI C define to be
  10692. whitespace?  Should \f be added too?
  10693.  
  10694. > 2) even if I fix whitespace in string.py, it is not being picked up
  10695. >    because it has been hardcoded in module strop to be space, \t and
  10696. >    \n. (string.py imports strop.)
  10697.  
  10698. Same reason, and I thought it wasn't ever going to matter.  Do you
  10699. think it is sufficient if I fix this by adding \r (and \f) to the
  10700. hardcoded list, or do you think we'll need a more general routine?
  10701.  
  10702. A possibility, if people think this is worth it, would be to somehow
  10703. find out which characters the C library's "isspace()" function
  10704. considers whitespace and use this definition throughout.
  10705.  
  10706. Feedback, please!
  10707.  
  10708. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  10709. 
  10710. 
  10711. Received: from att-out.att.com by charon.cwi.nl with SMTP
  10712.     id AA10123 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 12:25:18 +0200
  10713. From: hzsbg01!jbuhrma@hvgtw.att.com
  10714. Received: from hzsbc03 by hzsbg01 (4.1/SMI-4.1)
  10715.     id AA22295; Thu, 8 Jul 93 12:17:33 +0200
  10716. Date: Thu, 8 Jul 93 12:17:33 +0200
  10717. Original-From: hzsbg01!jbuhrma
  10718. Message-Id: <9307081017.AA22295@hzsbg01>
  10719. To: Guido.van.Rossum@cwi.nl
  10720. Subject: Re: strop module and whitespace
  10721.  
  10722. > Perhaps because \r is really a arbitrary control character (Python
  10723. > uses UNIX' convention that \n is the line separator).  Or perhaps it's
  10724. > an oversight.  What set of characters does ANSI C define to be
  10725. > whitespace?  Should \f be added too?
  10726.  
  10727. Yes, and don't forget the Vertical Tab.  I don't have any standards at
  10728. hand, but a simple program compiled on SunOS Release 4.1.3 (together
  10729. with data from ``man ascii'' and A2.5.2 from K&R's C manual (ANSI
  10730. version)) gives the following result:
  10731.  
  10732. HT       ^I '\t' (0011) isspace
  10733. NL  (LF) ^J '\n' (0012) isspace
  10734. VT       ^K '\v' (0013) isspace
  10735. NP  (FF) ^L '\f' (0014) isspace
  10736. CR       ^M '\r' (0015) isspace
  10737. SP          ' '  (0040) isspace
  10738.  
  10739. Can't strop use the ctype functions?  At least Python will behave then
  10740. exactly like a C program would do.
  10741.  
  10742. You could perhaps string.py be automatically generated from a C program
  10743. that reflects that same ``local taste'' (if it would differ anyways from
  10744. what's defined in some standard).
  10745.  
  10746. > Feedback, please!
  10747.  
  10748. Here you are...
  10749.  
  10750. -- Jan-Hein Buhrman -- AT&T Huizen NL -- <jbuhrma%hzsbg01@hvlpa.att.com> --
  10751. ---------------------- +31 35 87.4278 --- ...!att!hvlpa!hzsbg01!jbuhrma ---
  10752. ``There is a severe danger that we might finish the program today''
  10753. 
  10754. 
  10755. Received: from srv01s4.cas.org by charon.cwi.nl with SMTP
  10756.     id AA12517 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 13:29:58 +0200
  10757. Date: Thu, 8 Jul 93 07:29:50 EDT
  10758. From: jcv26@cas.org (Jon Vander Hill)
  10759. Message-Id: <9307081129.AA28405@cas.org>
  10760. To: Guido.van.Rossum@cwi.nl
  10761. Subject: Re: strop module and whitespace 
  10762. In-Reply-To: <9307080831.AA05505=guido@voorn.cwi.nl>
  10763. References: <9307072145.AA14590@eng2.sequent.com>
  10764.     <9307080831.AA05505=guido@voorn.cwi.nl>
  10765.  
  10766. >>>>> On Thu, 08 Jul 1993 10:31:47 +0200, Guido.van.Rossum@cwi.nl said:
  10767.  
  10768. >> 1) why is \r not considered whitespace?
  10769.  
  10770. > Perhaps because \r is really a arbitrary control character (Python
  10771. > uses UNIX' convention that \n is the line separator).  Or perhaps it's
  10772. > an oversight.  What set of characters does ANSI C define to be
  10773. > whitespace?  Should \f be added too?
  10774.  
  10775. >> 2) even if I fix whitespace in string.py, it is not being picked up
  10776. >>    because it has been hardcoded in module strop to be space, \t and
  10777. >>    \n. (string.py imports strop.)
  10778.  
  10779. > Same reason, and I thought it wasn't ever going to matter.  Do you
  10780. > think it is sufficient if I fix this by adding \r (and \f) to the
  10781. > hardcoded list, or do you think we'll need a more general routine?
  10782.  
  10783. > A possibility, if people think this is worth it, would be to somehow
  10784. > find out which characters the C library's "isspace()" function
  10785. > considers whitespace and use this definition throughout.
  10786.  
  10787. > Feedback, please!
  10788.  
  10789. In C source files, ANSI C defines whitespace to include tab (0x09),
  10790. newline (0x0a), vertical tab (0x0b), formfeed (0x0c), carriage return
  10791. (0x0d), space (0x20), and comments.  I don't have doc on the ANSI
  10792. C library routines.
  10793.  
  10794. The SunOS (non-ANSI) isspace() says all of the above (except comments)
  10795. are whitespace.
  10796.  
  10797. Jon Vander Hill
  10798. jon@cas.org
  10799.  
  10800.  
  10801. 
  10802. 
  10803. Received: from sun2.mhs-relay.ac.uk by charon.cwi.nl with SMTP
  10804.     id AA14883 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 14:30:30 +0200
  10805. Via: uk.ac.oxford.prg; Thu, 8 Jul 1993 13:29:56 +0100
  10806. Received: from uk.ac.oxford.robots (lucrece-gate.robots) by prg.oxford.ac.uk 
  10807.           id AA15947; Thu, 8 Jul 93 13:29:50 +0100
  10808. Received: from robots.ox.ac.uk (miranda.robots) 
  10809.           by uk.ac.oxford.robots (4.1/robots.1) id AA06273;
  10810.           Thu, 8 Jul 93 13:29:48 BST
  10811. Received: by robots.ox.ac.uk (4.1/robots.remoteV2.0) id AA15603;
  10812.           Thu, 8 Jul 93 13:29:47 BST
  10813. Date: Thu, 8 Jul 93 13:29:47 BST
  10814. From: peter@robots.oxford.ac.uk
  10815. Message-Id: <9307081229.AA15603@miranda.robots.ox.ac.uk>
  10816. To: Guido.van.Rossum@cwi.nl
  10817. Subject: Re: strop module and whitespace
  10818. Cc: python-list@cwi.nl
  10819.  
  10820. Guido writes:
  10821. > A possibility, if people think this is worth it, would be to somehow
  10822. > find out which characters the C library's "isspace()" function
  10823. > considers whitespace and use this definition throughout.
  10824. > Feedback, please!
  10825. > --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  10826.  
  10827. I think you could either have some kind of python variable (like sh's IFS)
  10828. or as you suggest just use the C isspace() function.  Both of these are
  10829. an improvement on the current hardcoded behaviour, especially if python has
  10830. the ability of running on multiple platforms.
  10831.  
  10832. Pete.
  10833. 
  10834. 
  10835. Received: from ohmg.hydro.on.ca by charon.cwi.nl with SMTP
  10836.     id AA17763 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 15:43:04 +0200
  10837. Received: from eagle.hydro.on.ca by ohmg.hydro.on.ca with SMTP id <66998>; Thu, 8 Jul 1993 09:47:57 -0400
  10838. Received: by eagle.hydro.on.ca (4.1/SMI-4.1)
  10839.     id AA21575; Thu, 8 Jul 93 09:42:03 EDT
  10840. Received: from thor.rd.hydro.on.ca by ohrd.rd.hydro.on.ca with SMTP id AA16527
  10841.   (5.65c/IDA-1.4.4 for Guido.van.Rossum@cwi.nl); Thu, 8 Jul 1993 09:52:37 -0400
  10842. Received: by thor.rd.hydro.on.ca id AA24280
  10843.   (5.65c/IDA-1.4.4 for python-list@cwi.nl); Thu, 8 Jul 1993 09:44:10 -0400
  10844. Date:     Thu, 8 Jul 1993 09:44:10 -0400
  10845. From: Martin Green <martin.a.green@hydro.on.ca>
  10846. Message-Id: <199307081344.AA24280@thor.rd.hydro.on.ca>
  10847. To: Guido.van.Rossum@cwi.nl
  10848. Cc: python-list@cwi.nl
  10849. Subject: Re: strop module and whitespace 
  10850. In-Reply-To: <9307080831.AA05505=guido@voorn.cwi.nl>
  10851. References: <9307072145.AA14590@eng2.sequent.com>
  10852.     <9307080831.AA05505=guido@voorn.cwi.nl>
  10853.  
  10854. On July 8 at 04:31:47 you (Guido.van.Rossum@cwi.nl) wrote:
  10855.  > 
  10856.  > A possibility, if people think this is worth it, would be to somehow
  10857.  > find out which characters the C library's "isspace()" function
  10858.  > considers whitespace and use this definition throughout.
  10859.  > 
  10860.  > Feedback, please!
  10861.  
  10862. The following program returns 9, 10, 11, 12, 13, 32 with SunOS 4.1.1.
  10863. I would suggest using these as defaults in a string of whitespace
  10864. characters that users can reassign if they want different behaviour.
  10865.  
  10866. ========================================================================
  10867. #include <stdio.h>
  10868. #include <ctype.h>
  10869. main()
  10870. {
  10871.     int i;
  10872.     for (i = 0; i < 256; i++) {
  10873.     if (isspace(i)) printf("%d\n", i);
  10874.     }
  10875. }
  10876. ========================================================================
  10877.  
  10878. Martin Green                        Net :  green@rd.hydro.on.ca
  10879. Ontario Hydro Research Division     Tel :  (416) 207-5745
  10880. 800 Kipling Ave,  KR260             FAX :  (416) 207-5622
  10881. Toronto, Ontario, CANADA, M8Z5S4
  10882. 
  10883. 
  10884. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  10885.     id AA24258 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 18:27:54 +0200
  10886. Received: by voorn.cwi.nl with SMTP
  10887.     id AA07059 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 18:27:53 +0200
  10888. Message-Id: <9307081627.AA07059=guido@voorn.cwi.nl>
  10889. To: python-list@cwi.nl
  10890. Subject: Re: strop module and whitespace 
  10891. In-Reply-To: Your message of "Wed, 07 Jul 1993 14:45:52 MDT."
  10892.              <9307072145.AA14590@eng2.sequent.com> 
  10893. From: Guido.van.Rossum@cwi.nl
  10894. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  10895. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  10896. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  10897. Date: Thu, 08 Jul 1993 18:27:53 +0200
  10898. Sender: Guido.van.Rossum@cwi.nl
  10899.  
  10900. Thanks for the feedback.  Now if everybody would also mail me their
  10901. opinion on the subject of the GREAT RENAMING...
  10902.  
  10903. I've chosen the following solution.  In the next release of Python,
  10904. the built-in module "strop" will export three variables: 'whitespace',
  10905. 'lowercase' and 'uppercase', constructing by testing isspace(),
  10906. islower() and isupper() for all characters in the range 1-255.  These
  10907. variables are inherited by the library module "string" (and its value
  10908. of 'digits' is correctly calculated).
  10909.  
  10910. I won't support changing these variables to modify the effect of the
  10911. corresponding built-in functions (strip(), split(), lower(), upper()
  10912. and swapcase()), since it would slow down their implementation
  10913. considerably -- they currently use the macros defined in <ctype.h>.
  10914. Of course the implementation could be made more efficient without
  10915. losing flexibility, but I personally doubt the usefulness of the
  10916. feature (especially since the effect would be global!), and I would
  10917. prefer to keep it small and simple.
  10918.  
  10919. If you need to have a version of split() that uses a different set of
  10920. characters, perhaps you can use regsub.split() instead -- it uses a
  10921. compiled regular expression for reasonable efficiency.  I might be
  10922. convinced that Python can use equivalents of strpbrk(), strspn(),
  10923. strcspn() and strtok() though (any other favorite string ops?).
  10924.  
  10925. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  10926. 
  10927. 
  10928. To: python-list@cwi.nl
  10929. Subject: Re: strop module and whitespace 
  10930. In-reply-to: Your message of "Wed, 07 Jul 1993 14:45:52 MDT."
  10931.              <9307072145.AA14590@eng2.sequent.com> 
  10932. From: Guido.van.Rossum@cwi.nl
  10933. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  10934. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  10935. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  10936. Date: Thu, 08 Jul 1993 18:27:53 +0200
  10937. Sender: guido
  10938.  
  10939. Thanks for the feedback.  Now if everybody would also mail me their
  10940. opinion on the subject of the GREAT RENAMING...
  10941.  
  10942. I've chosen the following solution.  In the next release of Python,
  10943. the built-in module "strop" will export three variables: 'whitespace',
  10944. 'lowercase' and 'uppercase', constructing by testing isspace(),
  10945. islower() and isupper() for all characters in the range 1-255.  These
  10946. variables are inherited by the library module "string" (and its value
  10947. of 'digits' is correctly calculated).
  10948.  
  10949. I won't support changing these variables to modify the effect of the
  10950. corresponding built-in functions (strip(), split(), lower(), upper()
  10951. and swapcase()), since it would slow down their implementation
  10952. considerably -- they currently use the macros defined in <ctype.h>.
  10953. Of course the implementation could be made more efficient without
  10954. losing flexibility, but I personally doubt the usefulness of the
  10955. feature (especially since the effect would be global!), and I would
  10956. prefer to keep it small and simple.
  10957.  
  10958. If you need to have a version of split() that uses a different set of
  10959. characters, perhaps you can use regsub.split() instead -- it uses a
  10960. compiled regular expression for reasonable efficiency.  I might be
  10961. convinced that Python can use equivalents of strpbrk(), strspn(),
  10962. strcspn() and strtok() though (any other favorite string ops?).
  10963.  
  10964. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  10965. 
  10966. 
  10967. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  10968.     id AA25344 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 18:49:32 +0200
  10969. To: Guido.van.Rossum@cwi.nl
  10970. Cc: jaap@sequent.com, python-list@cwi.nl
  10971. In-Reply-To: <9307080831.AA05505=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  10972. Subject: Re: strop module and whitespace 
  10973. Date: Thu, 8 Jul 93 9:48:30 PDT
  10974. From: lance@markv.com
  10975. Sender: lance@markv.com
  10976. Message-Id:  <9307080948.aa27197@hermix.markv.com>
  10977. Source-Info:  From (or Sender) name not authenticated.
  10978.  
  10979.  
  10980.    > 1) why is \r not considered whitespace?
  10981.  
  10982.    Perhaps because \r is really a arbitrary control character (Python
  10983.    uses UNIX' convention that \n is the line separator).  Or perhaps it's
  10984.    an oversight.  What set of characters does ANSI C define to be
  10985.    whitespace?  Should \f be added too?
  10986.  
  10987.    > 2) even if I fix whitespace in string.py, it is not being picked up
  10988.    >    because it has been hardcoded in module strop to be space, \t and
  10989.    >    \n. (string.py imports strop.)
  10990.  
  10991.    Same reason, and I thought it wasn't ever going to matter.  Do you
  10992.    think it is sufficient if I fix this by adding \r (and \f) to the
  10993.    hardcoded list, or do you think we'll need a more general routine?
  10994.  
  10995.    A possibility, if people think this is worth it, would be to somehow
  10996.    find out which characters the C library's "isspace()" function
  10997.    considers whitespace and use this definition throughout.
  10998.  
  10999.    Feedback, please!
  11000.  
  11001.  
  11002. Why not have the module at import time scan the ascii table and use
  11003. isspace() to find out the actual white space characters.. This would
  11004. not take much time and would only be done with the first instance of the
  11005. imported module. This will make it 100% machine independent.
  11006.  
  11007. Comments?
  11008.  
  11009. Lance Ellinghouse
  11010. lance@markv.com
  11011. 
  11012. 
  11013. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  11014.     id AA25481 (5.65b/3.8/CWI-Amsterdam); Thu, 8 Jul 1993 18:55:41 +0200
  11015. To: Guido.van.Rossum@cwi.nl
  11016. In-Reply-To: <9307081627.AA07059=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  11017. Subject: Re: strop module and whitespace 
  11018. Date: Thu, 8 Jul 93 9:54:38 PDT
  11019. From: lance@markv.com
  11020. Sender: lance@markv.com
  11021. Message-Id:  <9307080954.aa27547@hermix.markv.com>
  11022. Source-Info:  From (or Sender) name not authenticated.
  11023.  
  11024.  
  11025.    I might be
  11026.    convinced that Python can use equivalents of strpbrk(), strspn(),
  11027.    strcspn() and strtok() though (any other favorite string ops?).
  11028.  
  11029. I could use the strtok() function myself.. not sure about the rest though..
  11030.  
  11031. Lance Ellinghouse
  11032. lance@markv.vom
  11033. 
  11034. 
  11035. Replied: Thu, 29 Jul 1993 08:57:03 +0200
  11036. Replied: "python-list@cwi.nl "
  11037. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  11038.     id AA06874 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 05:04:27 +0200
  11039. From: Lance Ellinghouse <lance@markv.com>
  11040. X-Mailer: SCO System V Mail (version 3.2)
  11041. To: python-list@cwi.nl
  11042. Subject: How to tell if in a script...
  11043. Date: Wed, 28 Jul 93 20:03:55 PDT
  11044. Message-Id:  <9307282003.aa08579@hermix.markv.com>
  11045.  
  11046. Is there a way to tell from inside a module if you are in an import
  11047. statement or loading from a script?
  11048.  
  11049. I have a .py file that can be loaded via 'import' or run from
  11050. the command line..
  11051.  
  11052. Also, is there a way to tell if this module is loaded for the first time
  11053. or if it is being reloaded via 'reload'???
  11054.  
  11055. I have a couple modules that MUST save state from import to reload.
  11056.  
  11057. --
  11058.  
  11059. Lance Ellinghouse           lance@markv.com
  11060.  
  11061. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  11062. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  11063. You can recieve my Public Key by `finger lance@mark.com`
  11064. 
  11065. 
  11066. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  11067.     id AA08552 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 08:57:04 +0200
  11068. Received: by voorn.cwi.nl with SMTP
  11069.     id AA09070 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 08:57:04 +0200
  11070. Message-Id: <9307290657.AA09070=guido@voorn.cwi.nl>
  11071. To: python-list@cwi.nl
  11072. Subject: Re: How to tell if in a script... 
  11073. In-Reply-To: Your message of "Wed, 28 Jul 1993 20:03:55 MDT."
  11074.              <9307282003.aa08579@hermix.markv.com> 
  11075. From: Guido.van.Rossum@cwi.nl
  11076. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  11077. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  11078. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  11079. Date: Thu, 29 Jul 1993 08:57:03 +0200
  11080. Sender: Guido.van.Rossum@cwi.nl
  11081.  
  11082. Lance Ellinghouse:
  11083.  
  11084. > Is there a way to tell from inside a module if you are in an import
  11085. > statement or loading from a script?
  11086.  
  11087. One trick that works:
  11088.  
  11089.     running_as_script = 0
  11090.     xxx = [] # create a unique object
  11091.     import __main__ # the toplevel script being run
  11092.     try:
  11093.         if __main__.xxx is xxx:
  11094.             running_as_script = 1
  11095.     except AttributeError:
  11096.         pass
  11097.  
  11098. Note the use of 'is' for the comparison, this compares object
  11099. identities instead of values.
  11100.  
  11101. Essentially the same code can be used for testing whether you have
  11102. been imported before (and hence are now being reloaded), by moving the
  11103. assignment to xxx after the try..except block (and changing the name
  11104. of the Boolean to something more meaningful, like impoerted_before).
  11105.  
  11106. 
  11107. 
  11108. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  11109.     id AA24172 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 16:57:16 +0200
  11110. Received: by voorn.cwi.nl with SMTP
  11111.     id AA17753 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 16:57:16 +0200
  11112. Message-Id: <9307291457.AA17753=guido@voorn.cwi.nl>
  11113. To: python-list@cwi.nl
  11114. Subject: Python 0.9.9 is out!
  11115. From: Guido.van.Rossum@cwi.nl
  11116. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  11117. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  11118. Date: Thu, 29 Jul 1993 16:57:15 +0200
  11119. Sender: Guido.van.Rossum@cwi.nl
  11120.  
  11121. The subject says it all: I've finally gotten the courage to release
  11122. Python 0.9.9.  For the most part, it's as rock solid as previous
  11123. releases.  It also contains direct X11 support (Xt, with a choice
  11124. between Athena or Motif widgets); however, that part of the release
  11125. should be considered beta software.
  11126.  
  11127. Ftp availability: ftp.cwi.nl:/pub/python; read the file INDEX for
  11128. details.  Files with "0.9.9" in them are obvious candidates for
  11129. retrieval :-).  There is also a Mac binary (no time to add the cute
  11130. "16 tons" icon alas).  I'm afraid there's no MS-DOS binary yet.
  11131.  
  11132. Some highlights:
  11133.  
  11134. * __init__ and __del__ methods to initialize and destroy class
  11135. instances
  11136.  
  11137. * more command line options, better usage message
  11138.  
  11139. * no need to use \ for continuation lines within matching brackets
  11140.  
  11141. * improved python-mode.el for Emacs
  11142.  
  11143. * sprintf-like functionality using 'formatstring' % (var1, var2, ...)
  11144.  
  11145. * dictionary keys can be other types than strings
  11146.  
  11147. * array data type (mutable sequence of fixed-size numbers)
  11148.  
  11149. * C-like functions for time conversions in module time: localtime,
  11150. asctime, mktime etc.
  11151.  
  11152. * Support for creating stand-alone executable binaries from Python
  11153. scripts
  11154.  
  11155. CAVEAT: I will be away for 7 weeks starting August 2; problems with
  11156. the distribution are best discussed on the mailing list.
  11157.  
  11158. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  11159. 
  11160. 
  11161. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  11162.     id AA01013 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 19:45:33 +0200
  11163. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11629>; Thu, 29 Jul 1993 10:45:11 PDT
  11164. Received: by eros.EuroPARC.Xerox.COM with SMTP
  11165.     (5.65c/IDA-1.2.9) id AA05034; Thu, 29 Jul 1993 18:44:09 +0100
  11166. Message-Id: <199307291744.AA05034@eros.EuroPARC.Xerox.COM>
  11167. To: Guido.van.Rossum@cwi.nl
  11168. Cc: python-list@cwi.nl
  11169. Subject: Re: Python 0.9.9 is out! 
  11170. In-Reply-To: Your message of "Thu, 29 Jul 93 07:57:15 PDT."
  11171.              <9307291457.AA17753=guido@voorn.cwi.nl> 
  11172. Date:     Thu, 29 Jul 1993 10:44:06 PDT
  11173. From: Fraser@europarc.xerox.com
  11174.  
  11175.  
  11176. Well, it built smoothly for me (on a sun) except:
  11177.  
  11178. * It did need X11R5 to build the X stuff
  11179.  
  11180. * stdwinmodule.c I think refers to a new stdwin? It didn't know what a 
  11181.   BITMAP was, nor about the calls:
  11182.  
  11183.    _wsetwinpos
  11184.    _wsetwinsize
  11185.    _wlistfontnames
  11186.  
  11187.   I bypassed these bits and it built OK.
  11188.  
  11189. Great Stuff!
  11190. Quentin
  11191.  
  11192.  
  11193. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11194. Quentin Stafford-Fraser                        Tel:  +44 223 341521             
  11195. Rank Xerox EuroPARC,                           Fax:  +44 223 341510     
  11196. 61 Regent Street,                              Home: +44 223 324451
  11197. Cambridge, CB2 1AB
  11198. United Kingdom                                 Fraser@europarc.xerox.com 
  11199. 
  11200. 
  11201. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  11202.     id AA09931 (5.65b/3.8/CWI-Amsterdam); Thu, 29 Jul 1993 23:06:24 +0200
  11203. From: Lance Ellinghouse <lance@markv.com>
  11204. X-Mailer: SCO System V Mail (version 3.2)
  11205. To: python-list@cwi.nl
  11206. Subject: diffs for socketmodule.c
  11207. Date: Thu, 29 Jul 93 14:06:04 PDT
  11208. Message-Id:  <9307291406.aa17594@hermix.markv.com>
  11209.  
  11210. To get python0.9.9 to compile I have had to make a number of changes..
  11211. I am compiling under SCO ODT 2.0 and I will send the changes as
  11212. I make them..
  11213.  
  11214. the first set is to socketmodule.c. 
  11215. Basicly SCO has no idea about AF_UNIX. Thus I remove
  11216. ALL instances of AF_UNIX with "#ifndef M_UNIX".
  11217.  
  11218. Here are the diffs...
  11219.  
  11220.  
  11221. --
  11222.  
  11223. Lance Ellinghouse           lance@markv.com
  11224.  
  11225. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  11226. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  11227. You can recieve my Public Key by `finger lance@mark.com`
  11228. ==== Diffs
  11229.  
  11230. 81d80
  11231. < #ifndef M_UNIX
  11232. 83d81
  11233. < #endif
  11234. 238d235
  11235. < #ifndef M_UNIX
  11236. 244d240
  11237. < #endif
  11238. 270d265
  11239. < #ifndef M_UNIX
  11240. 288d282
  11241. < #endif
  11242. 327d320
  11243. < #ifndef M_UNIX
  11244. 333d325
  11245. < #endif
  11246. 1071d1062
  11247. < #ifndef M_UNIX
  11248. 1073d1063
  11249. < #endif
  11250. 
  11251. 
  11252. Replied: Fri, 30 Jul 1993 10:23:20 +0200
  11253. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list"
  11254. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  11255.     id AA21218 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 02:03:23 +0200
  11256. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  11257.     id AA17241; Thu, 29 Jul 93 17:00:09 -0700
  11258. Received: by eng2.sequent.com (5.65/1.34)
  11259.     id AA20780; Thu, 29 Jul 93 17:03:12 -0700
  11260. Message-Id: <9307300003.AA20780@eng2.sequent.com>
  11261. To: python-list@cwi.nl
  11262. Subject: Why does only sgi have DO_PG in posixmodule.c
  11263. Priority: Normal
  11264. Precedence: first-class
  11265. Organization: Sequent Computer Systems, Inc.
  11266.           Service Technology - MailStop: WIL2-610
  11267.           15450 S.W. Koll Parkway
  11268.           Beaverton, OR  97006-6063
  11269. X-Phone: (503) 578-4404
  11270. X-Fax: (503) 578-4540
  11271. X-Uucp: ...!uunet!sequent!jaap
  11272. X-Internet: jaap@sequent.com
  11273. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  11274.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  11275.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  11276. Date: Thu, 29 Jul 1993 17:03:10 -0700
  11277. From: Jaap Vermeulen <jaap@sequent.com>
  11278.  
  11279.  
  11280. At the top of the file it sez:
  11281.  
  11282. #ifdef __sgi
  11283. #define DO_PG
  11284. #endif
  11285.  
  11286. Guess what, these process group commands come in handy, especially if
  11287. you want to create a daemon (setsid).  Actually, you can't create a
  11288. daemon without those routines.  Can't we include them by default?
  11289.  
  11290. As a side issue, does python still print to stderr internally, no
  11291. matter what you set sys.stderr to?  That is very annoying if you try to
  11292. make it shut up completely.
  11293.  
  11294. Thanks,
  11295.  
  11296.     -Jaap-
  11297. --
  11298. Jaap Vermeulen                    +--------------------------+
  11299.                         | Sequent Computer Systems |
  11300.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  11301.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  11302. 
  11303. 
  11304. Replied: Fri, 30 Jul 1993 10:28:49 +0200
  11305. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list@cwi.nl"
  11306. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  11307.     id AA22223 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 02:10:35 +0200
  11308. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  11309.     id AA17445; Thu, 29 Jul 93 17:07:26 -0700
  11310. Received: by eng2.sequent.com (5.65/1.34)
  11311.     id AA22662; Thu, 29 Jul 93 17:10:27 -0700
  11312. Message-Id: <9307300010.AA22662@eng2.sequent.com>
  11313. To: python-list@cwi.nl
  11314. Subject: The new freeze code
  11315. Priority: Normal
  11316. Precedence: first-class
  11317. Organization: Sequent Computer Systems, Inc.
  11318.           Service Technology - MailStop: WIL2-610
  11319.           15450 S.W. Koll Parkway
  11320.           Beaverton, OR  97006-6063
  11321. X-Phone: (503) 578-4404
  11322. X-Fax: (503) 578-4540
  11323. X-Uucp: ...!uunet!sequent!jaap
  11324. X-Internet: jaap@sequent.com
  11325. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  11326.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  11327.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  11328. Date: Thu, 29 Jul 1993 17:10:26 -0700
  11329. From: Jaap Vermeulen <jaap@sequent.com>
  11330.  
  11331.  
  11332. I tried it: very nifty indeed.
  11333.  
  11334. However, it seems like I get dumped into the interpreter after the the
  11335. script is done running.  I tried the script freeze.py on the script
  11336. dutree.py.  Is this intentional, or is something wrong?
  11337.  
  11338. As a side comment, it's better to use 'unsigned char' for 8 bit code,
  11339. so that the ansi compiler doesn't complain all the time about
  11340. '"./frozen.c", line x: warning: initializer does not fit: xxx'.
  11341.  
  11342.                         print 'static unsigned char M_' + mod + '[' + \
  11343.                       ^^^^^^^^
  11344. and
  11345.         print '  unsigned char *code;'
  11346.              ^^^^^^^^
  11347. (the ^^^ piece is proposed).
  11348.  
  11349. Thanks,
  11350.  
  11351.     -Jaap-
  11352. --
  11353. Jaap Vermeulen                    +--------------------------+
  11354.                         | Sequent Computer Systems |
  11355.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  11356.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  11357. 
  11358. 
  11359. Replied: Fri, 30 Jul 1993 10:36:49 +0200
  11360. Replied: "lance@markv.com python-list@cwi.nl"
  11361. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  11362.     id AA23770 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 02:20:36 +0200
  11363. To: python-list@cwi.nl
  11364. Subject: revised import.c
  11365. Date: Thu, 29 Jul 93 17:20:04 PDT
  11366. From: lance@markv.com
  11367. Sender: lance@markv.com
  11368. Message-Id:  <9307291720.aa01937@hermix.markv.com>
  11369. Source-Info:  From (or Sender) name not authenticated.
  11370.  
  11371.  
  11372. I have merged my changes to import.c into the 0.9.9 version.
  11373. Here are the diffs for the 0.9.9 version that allow you to have
  11374. a .pyc file without the .py file being present. Again, this still
  11375. needs to be tested by someone that uses dynamic linking as I don't.
  11376.  
  11377. Enjoy!
  11378.  
  11379. *** import.c    Tue May 25 02:38:24 1993
  11380. --- import.c.new    Thu Jul 29 17:10:14 1993
  11381. ***************
  11382. *** 38,45 ****
  11383. --- 38,56 ----
  11384.   #include "eval.h"
  11385.   #include "osdefs.h"
  11386.   
  11387. + #include <unistd.h>
  11388. + #include <sys/stat.h>
  11389.   extern int verbose; /* Defined in pythonmain.c */
  11390.   
  11391. + #ifndef FALSE
  11392. + #define FALSE 0
  11393. + #endif
  11394. + #ifndef TRUE
  11395. + #define TRUE 1
  11396. + #endif
  11397.   #ifdef DEBUG
  11398.   #define D(x) x
  11399.   #else
  11400. ***************
  11401. *** 97,137 ****
  11402.   /* Suffixes used by open_module: */
  11403.   
  11404.   #define PY_SUFFIX    ".py"
  11405.   #ifdef USE_DL
  11406.   #define O_SUFFIX    "module.o"
  11407.   #endif
  11408.   
  11409. ! /* Find and open a module file, using sys.path.
  11410. !    Return a NULL pointer if no module file is found.
  11411. !    When dynamic loading is enabled, the contents of namebuf
  11412. !    is important when NULL is returned: if namebuf[0] != '\0'
  11413. !    a dl-able object file was found and namebuf is its pathname. */
  11414. ! static FILE *
  11415. ! open_module(name, namebuf)
  11416.       char *name;
  11417. !     char *namebuf; /* XXX No buffer overflow checks! */
  11418.   {
  11419.       object *path;
  11420. !     FILE *fp;
  11421. !     
  11422.       path = sysget("path");
  11423.       if (path == NULL || !is_listobject(path)) {
  11424.           /* No path -- at least try current directory */
  11425. - #ifdef USE_DL
  11426. -         strcpy(namebuf, name);
  11427. -         strcat(namebuf, O_SUFFIX);
  11428. -         if (getmtime(namebuf) > 0)
  11429. -             return NULL;
  11430. - #endif
  11431.           strcpy(namebuf, name);
  11432. !         strcat(namebuf, PY_SUFFIX);
  11433. !         fp = fopen(namebuf, "r");
  11434. !     }
  11435. !     else {
  11436.           int npath = getlistsize(path);
  11437.           int i;
  11438. -         fp = NULL;
  11439.           for (i = 0; i < npath; i++) {
  11440.               object *v = getlistitem(path, i);
  11441.               int len;
  11442. --- 108,146 ----
  11443.   /* Suffixes used by open_module: */
  11444.   
  11445.   #define PY_SUFFIX    ".py"
  11446. + #define PYC_SUFFIX    ".pyc"
  11447.   #ifdef USE_DL
  11448.   #define O_SUFFIX    "module.o"
  11449.   #endif
  11450.   
  11451. ! /* This will search for a module named 'name' with the extension 'ext'
  11452. !    and return it in 'namebuf' and return the mtime of each in 'mtime'
  11453. !    it will return TRUE if it found it, FALSE if it does not.
  11454. !  */
  11455. ! static int
  11456. ! find_module(name, ext, namebuf, mtime)
  11457.       char *name;
  11458. !     char *ext;
  11459. !     char *namebuf;
  11460. !     time_t *mtime;
  11461.   {
  11462.       object *path;
  11463. !     struct stat s;
  11464.       path = sysget("path");
  11465.       if (path == NULL || !is_listobject(path)) {
  11466.           /* No path -- at least try current directory */
  11467.           strcpy(namebuf, name);
  11468. !         strcat(namebuf, ext);
  11469. !         if (stat(namebuf,&s) == -1)
  11470. !             return FALSE;
  11471. !         if (access(namebuf,R_OK) == -1)
  11472. !             return FALSE;
  11473. !         *mtime = s.st_mtime;
  11474. !         return TRUE;
  11475. !     } else {
  11476.           int npath = getlistsize(path);
  11477.           int i;
  11478.           for (i = 0; i < npath; i++) {
  11479.               object *v = getlistitem(path, i);
  11480.               int len;
  11481. ***************
  11482. *** 141,162 ****
  11483.               len = getstringsize(v);
  11484.               if (len > 0 && namebuf[len-1] != SEP)
  11485.                   namebuf[len++] = SEP;
  11486. - #ifdef USE_DL
  11487.               strcpy(namebuf+len, name);
  11488. !             strcat(namebuf, O_SUFFIX);
  11489. !             if (getmtime(namebuf) > 0)
  11490. !                 return NULL;
  11491. ! #endif
  11492. !             strcpy(namebuf+len, name);
  11493. !             strcat(namebuf, PY_SUFFIX);
  11494. !             fp = fopen(namebuf, "r");
  11495. !             if (fp != NULL)
  11496. !                 break;
  11497.           }
  11498.       }
  11499. !     if (fp == NULL)
  11500. !         namebuf[0] = '\0';
  11501. !     return fp;
  11502.   }
  11503.   
  11504.   static object *
  11505. --- 150,167 ----
  11506.               len = getstringsize(v);
  11507.               if (len > 0 && namebuf[len-1] != SEP)
  11508.                   namebuf[len++] = SEP;
  11509.               strcpy(namebuf+len, name);
  11510. !             strcat(namebuf, ext);
  11511. !             if (stat(namebuf,&s) == -1)
  11512. !                 continue;
  11513. !             if (access(namebuf,R_OK) == -1)
  11514. !                 continue;
  11515. !             *mtime = s.st_mtime;
  11516. !             return TRUE;
  11517.           }
  11518.       }
  11519. !     namebuf[0] = '\0';
  11520. !     return FALSE;
  11521.   }
  11522.   
  11523.   static object *
  11524. ***************
  11525. *** 175,183 ****
  11526.       long mtime;
  11527.       extern long getmtime();
  11528.       
  11529. !     fp = open_module(name, namebuf);
  11530. !     if (fp == NULL) {
  11531.   #ifdef USE_DL
  11532.           if (namebuf[0] != '\0') {
  11533.               char funcname[258];
  11534.               dl_funcptr p;
  11535. --- 180,188 ----
  11536.       long mtime;
  11537.       extern long getmtime();
  11538.       
  11539.   #ifdef USE_DL
  11540. +     if (find_module(name,O_SUFFIX,namebuf,&mtime)) {
  11541.           if (namebuf[0] != '\0') {
  11542.               char funcname[258];
  11543.               dl_funcptr p;
  11544. ***************
  11545. *** 186,193 ****
  11546.               p =  dl_loadmod(argv0, namebuf, funcname);
  11547.               if (p == NULL) {
  11548.                   D(fprintf(stderr, "dl_loadmod failed\n"));
  11549. !             }
  11550. !             else {
  11551.                   if (verbose)
  11552.                       fprintf(stderr,
  11553.                   "import %s # dynamically loaded from \"%s\"\n",
  11554. --- 191,197 ----
  11555.               p =  dl_loadmod(argv0, namebuf, funcname);
  11556.               if (p == NULL) {
  11557.                   D(fprintf(stderr, "dl_loadmod failed\n"));
  11558. !             } else {
  11559.                   if (verbose)
  11560.                       fprintf(stderr,
  11561.                   "import %s # dynamically loaded from \"%s\"\n",
  11562. ***************
  11563. *** 198,205 ****
  11564.                       err_setstr(SystemError,
  11565.                              "dynamic module missing");
  11566.                       return NULL;
  11567. !                 }
  11568. !                 else {
  11569.                       D(fprintf(stderr,
  11570.                           "module %s loaded!\n", name));
  11571.                       INCREF(None);
  11572. --- 202,208 ----
  11573.                       err_setstr(SystemError,
  11574.                              "dynamic module missing");
  11575.                       return NULL;
  11576. !                 } else {
  11577.                       D(fprintf(stderr,
  11578.                           "module %s loaded!\n", name));
  11579.                       INCREF(None);
  11580. ***************
  11581. *** 207,213 ****
  11582. --- 210,272 ----
  11583.                   }
  11584.               }
  11585.           }
  11586. +     } else
  11587.   #endif
  11588. +     if (find_module(name,PYC_SUFFIX,namebuf,&mtime)) {
  11589. + read_pyc:
  11590. +         fpc = fopen(namebuf, "rb");
  11591. +         namebuf[(strlen(namebuf)-1)] = '\0';
  11592. +         mtime = getmtime(namebuf);
  11593. +         if (fpc != NULL) {
  11594. +             long pyc_mtime;
  11595. +             long magic;
  11596. +             magic = rd_long(fpc);
  11597. +             pyc_mtime = rd_long(fpc);
  11598. +             if (mtime != -1 && mtime > pyc_mtime) {
  11599. +                 fclose(fpc);
  11600. +                 goto read_py;
  11601. +             }
  11602. +             if (magic == MAGIC) {
  11603. +                 v = rd_object(fpc);
  11604. +                 if (v == NULL || err_occurred() || !is_codeobject(v)) {
  11605. +                     err_clear();
  11606. +                     XDECREF(v);
  11607. +                 }
  11608. +                 else
  11609. +                     co = (codeobject *)v;
  11610. +             }
  11611. +             fclose(fpc);
  11612. +             if (verbose) {
  11613. +                 if (co != NULL)
  11614. +                     fprintf(stderr,
  11615. +                     "import %s # precompiled from \"%s\"\n",
  11616. +                         name, namebuf);
  11617. +                 else
  11618. +                     fprintf(stderr,
  11619. +                         "# invalid precompiled file \"%s\"\n",
  11620. +                         namebuf);
  11621. +             }
  11622. +         }
  11623. +     } else if (find_module(name,PY_SUFFIX,namebuf,&mtime)) {
  11624. + read_py:
  11625. +         fp = fopen(namebuf,"rb");
  11626. +         namelen = strlen(namebuf);
  11627. +         if (co == NULL) {
  11628. +             if (verbose)
  11629. +                 fprintf(stderr,
  11630. +                     "import %s # from \"%s\"\n",
  11631. +                     name, namebuf);
  11632. +             err = parse_file(fp, namebuf, file_input, &n);
  11633. +         } else
  11634. +             err = E_DONE;
  11635. +         fclose(fp);
  11636. +         if (err != E_DONE) {
  11637. +             err_input(err);
  11638. +             return NULL;
  11639. +         }
  11640. +     } else {
  11641.           if (m == NULL) {
  11642.               sprintf(namebuf, "no module named %.200s", name);
  11643.               err_setstr(ImportError, namebuf);
  11644. ***************
  11645. *** 216,269 ****
  11646.               sprintf(namebuf, "no source for module %.200s", name);
  11647.               err_setstr(ImportError, namebuf);
  11648.           }
  11649. -         return NULL;
  11650. -     }
  11651. -     /* Get mtime -- always useful */
  11652. -     mtime = getmtime(namebuf);
  11653. -     /* Check ".pyc" file first */
  11654. -     namelen = strlen(namebuf);
  11655. -     namebuf[namelen] = 'c';
  11656. -     namebuf[namelen+1] = '\0';
  11657. -     fpc = fopen(namebuf, "rb");
  11658. -     if (fpc != NULL) {
  11659. -         long pyc_mtime;
  11660. -         long magic;
  11661. -         magic = rd_long(fpc);
  11662. -         pyc_mtime = rd_long(fpc);
  11663. -         if (magic == MAGIC && pyc_mtime == mtime && mtime != 0 && mtime != -1) {
  11664. -             v = rd_object(fpc);
  11665. -             if (v == NULL || err_occurred() || !is_codeobject(v)) {
  11666. -                 err_clear();
  11667. -                 XDECREF(v);
  11668. -             }
  11669. -             else
  11670. -                 co = (codeobject *)v;
  11671. -         }
  11672. -         fclose(fpc);
  11673. -         if (verbose) {
  11674. -             if (co != NULL)
  11675. -                 fprintf(stderr,
  11676. -                 "import %s # precompiled from \"%s\"\n",
  11677. -                     name, namebuf);
  11678. -             else
  11679. -                 fprintf(stderr,
  11680. -                     "# invalid precompiled file \"%s\"\n",
  11681. -                     namebuf);
  11682. -         }
  11683. -     }
  11684. -     namebuf[namelen] = '\0';
  11685. -     if (co == NULL) {
  11686. -         if (verbose)
  11687. -             fprintf(stderr,
  11688. -                 "import %s # from \"%s\"\n",
  11689. -                 name, namebuf);
  11690. -         err = parse_file(fp, namebuf, file_input, &n);
  11691. -     }
  11692. -     else
  11693. -         err = E_DONE;
  11694. -     fclose(fp);
  11695. -     if (err != E_DONE) {
  11696. -         err_input(err);
  11697.           return NULL;
  11698.       }
  11699.       if (m == NULL) {
  11700. --- 275,280 ----
  11701.  
  11702. --
  11703.  
  11704. Lance Ellinghouse           lance@markv.com
  11705.  
  11706. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  11707. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  11708. You can recieve my Public Key by `finger lance@mark.com`
  11709. 
  11710. 
  11711. Replied: Fri, 30 Jul 1993 10:40:14 +0200
  11712. Replied: "Lance Ellinghouse <lance@markv.com> python-list@cwi.nl"
  11713. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  11714.     id AA00633 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 07:51:22 +0200
  11715. From: Lance Ellinghouse <lance@markv.com>
  11716. X-Mailer: SCO System V Mail (version 3.2)
  11717. To: python-list@cwi.nl
  11718. Subject: JPEG module....
  11719. Date: Thu, 29 Jul 93 22:51:04 PDT
  11720. Message-Id:  <9307292251.aa22355@hermix.markv.com>
  11721.  
  11722. Where can I get the libraries needed for the JPEG module?
  11723.  
  11724. Thanks!
  11725.  
  11726.  
  11727. --
  11728.  
  11729. Lance Ellinghouse           lance@markv.com
  11730.  
  11731. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  11732. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  11733. You can recieve my Public Key by `finger lance@mark.com`
  11734. 
  11735. 
  11736. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  11737.     id AA06424 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:23:22 +0200
  11738. Received: by voorn.cwi.nl with SMTP
  11739.     id AA18847 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:23:21 +0200
  11740. Message-Id: <9307300823.AA18847=guido@voorn.cwi.nl>
  11741. To: Jaap Vermeulen <jaap@sequent.com>
  11742. Cc: python-list@cwi.nl
  11743. Subject: Re: Why does only sgi have DO_PG in posixmodule.c 
  11744. In-Reply-To: Your message of "Thu, 29 Jul 1993 17:03:10 MDT."
  11745.              <9307300003.AA20780@eng2.sequent.com> 
  11746. From: Guido.van.Rossum@cwi.nl
  11747. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  11748. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  11749. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  11750. Date: Fri, 30 Jul 1993 10:23:20 +0200
  11751. Sender: Guido.van.Rossum@cwi.nl
  11752.  
  11753. > At the top of the file it sez:
  11754. > #ifdef __sgi
  11755. > #define DO_PG
  11756. > #endif
  11757. > Guess what, these process group commands come in handy, especially if
  11758. > you want to create a daemon (setsid).  Actually, you can't create a
  11759. > daemon without those routines.  Can't we include them by default?
  11760.  
  11761. Not all systems support this, especially SunOS 4 doesn't.  It should
  11762. have been made a "Configure" time option.
  11763.  
  11764. > As a side issue, does python still print to stderr internally, no
  11765. > matter what you set sys.stderr to?  That is very annoying if you try to
  11766. > make it shut up completely.
  11767.  
  11768. There is some output to stderr, but only if the interpreter gets
  11769. seriously confused.  Stack traces go to whatever sys.stderr points to.
  11770.  
  11771. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  11772. 
  11773. 
  11774. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  11775.     id AA06924 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:36:52 +0200
  11776. Received: by voorn.cwi.nl with SMTP
  11777.     id AA18885 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:36:50 +0200
  11778. Message-Id: <9307300836.AA18885=guido@voorn.cwi.nl>
  11779. To: lance@markv.com
  11780. Cc: python-list@cwi.nl
  11781. Subject: Re: revised import.c 
  11782. In-Reply-To: Your message of "Thu, 29 Jul 1993 17:20:04 MDT."
  11783.              <9307291720.aa01937@hermix.markv.com> 
  11784. From: Guido.van.Rossum@cwi.nl
  11785. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  11786. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  11787. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  11788. Date: Fri, 30 Jul 1993 10:36:49 +0200
  11789. Sender: Guido.van.Rossum@cwi.nl
  11790.  
  11791. > I have merged my changes to import.c into the 0.9.9 version.
  11792. > Here are the diffs for the 0.9.9 version that allow you to have
  11793. > a .pyc file without the .py file being present. Again, this still
  11794. > needs to be tested by someone that uses dynamic linking as I don't.
  11795.  
  11796. I can see why you'd want this in certain cases, but when I designed
  11797. this code I made a conscious decision to require that the .py should
  11798. file be there for the .pyc file to be valid -- unlike Emacs .elc
  11799. files, .pyc files can be considered as pure caches and are managed
  11800. completely automatic.  Perhaps Lance's version can be made into a
  11801. compile-time or run-time option?
  11802.  
  11803. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  11804. 
  11805. 
  11806. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  11807.     id AA07056 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:40:16 +0200
  11808. Received: by voorn.cwi.nl with SMTP
  11809.     id AA18904 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:40:14 +0200
  11810. Message-Id: <9307300840.AA18904=guido@voorn.cwi.nl>
  11811. To: Lance Ellinghouse <lance@markv.com>
  11812. Cc: python-list@cwi.nl
  11813. Subject: Re: JPEG module.... 
  11814. In-Reply-To: Your message of "Thu, 29 Jul 1993 22:51:04 MDT."
  11815.              <9307292251.aa22355@hermix.markv.com> 
  11816. From: Guido.van.Rossum@cwi.nl
  11817. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  11818. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  11819. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  11820. Date: Fri, 30 Jul 1993 10:40:14 +0200
  11821. Sender: Guido.van.Rossum@cwi.nl
  11822.  
  11823. > Where can I get the libraries needed for the JPEG module?
  11824.  
  11825. Oops, I should have placed a pointer somewhere.  From the README file
  11826. of the jpeg code:
  11827.  
  11828. |README for release of  7-Oct-91
  11829. |===============================
  11830. |
  11831. |This distribution contains the first public release of the Independent JPEG
  11832. |Group's free JPEG software.  You are welcome to redistribute this software and
  11833. |to use it for any purpose, subject to the conditions under LEGAL ISSUES, below
  11834. |
  11835. |This software is still undergoing revision.  Updated versions may be obtained
  11836. |by anonymous FTP to uunet.uu.net; look under directory /graphics/jpeg.  This
  11837. |particular version will be archived as jpegsrc.v1.tar.Z.  If you don't have
  11838. |access to Internet FTP, UUNET's archives are also available via UUCP; contact
  11839. |postmaster@uunet.uu.net for information on retrieving files that way.
  11840. |
  11841. |Please report any problems with this software to jpeg-info@uunet.uu.net.
  11842.  
  11843. I believe this isn't the latest but I expect that at least one of the
  11844. mentioned locations or email addresses still works...
  11845.  
  11846. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  11847. 
  11848. 
  11849. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  11850.     id AA07407 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 10:48:17 +0200
  11851. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11600>; Fri, 30 Jul 1993 01:47:49 PDT
  11852. Received: by eros.EuroPARC.Xerox.COM with SMTP
  11853.     (5.65c/IDA-1.2.9) id AA07971; Fri, 30 Jul 1993 09:47:14 +0100
  11854. Message-Id: <199307300847.AA07971@eros.EuroPARC.Xerox.COM>
  11855. To: python-list@cwi.nl
  11856. Subject: Bitmaps
  11857. In-Reply-To: Your message of "Thu, 29 Jul 93 07:57:15 PDT."
  11858.              <9307291457.AA17753=guido@voorn.cwi.nl> 
  11859. Date:     Fri, 30 Jul 1993 01:47:09 PDT
  11860. From: Fraser@europarc.xerox.com
  11861.  
  11862.  
  11863. Well, I read the NEWS file, and it said that you might need the
  11864. version of stdwin for Views, so I got that, but it still doesn't seem
  11865. to have the bitmap stuff that stdwinmodule is looking for. My hacked
  11866. version seems to work ok, though, so I'll wait until Guido gets back.
  11867.  
  11868. Talking of Guido, if, like me, you haven't met him and wonder what he
  11869. looks like, tell xmosaic to open the CWI home page, which I found at
  11870. ftp://ftp.cwi.nl/pub/www/default.html. If you don't have xmosaic, I
  11871. strongly recommend that you get a copy! (from ftp.ncsa.uiuc.edu)
  11872.  
  11873. Quentin
  11874.  
  11875.  
  11876. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  11877. Quentin Stafford-Fraser                        Tel:  +44 223 341521             
  11878. Rank Xerox EuroPARC,                           Fax:  +44 223 341510     
  11879. 61 Regent Street,                              Home: +44 223 324451
  11880. Cambridge, CB2 1AB
  11881. United Kingdom                                 Fraser@europarc.xerox.com 
  11882.  
  11883. 
  11884. 
  11885. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  11886.     id AA12390 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 12:38:55 +0200
  11887. Received: by schelvis.cwi.nl with SMTP
  11888.     id AA02228 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 12:38:55 +0200
  11889. Message-Id: <9307301038.AA02228=jack@schelvis.cwi.nl>
  11890. To: python-list@cwi.nl
  11891. Subject: JPEG in python
  11892. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  11893. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  11894. X-Last-Band-Seen: Beat Busters, Desmond Dekker (Paradiso, 24-7)
  11895. X-Mini-Review: Uptown top skanking!
  11896. Date: Fri, 30 Jul 1993 12:38:54 +0200
  11897. From: Jack Jansen <Jack.Jansen@cwi.nl>
  11898.  
  11899. Actually, the jpeg module in python needs my mucho-hacked-up version
  11900. of a very old jpeg distribution. I had to hack in memory-to-memory
  11901. conversion of jpeg data. (Hey, that's nice, the three 'jpeg's align
  11902. nicely:-) I'll be gone for 10 days, but when I come back I'll try to
  11903. whip something up with a newer jpeg version that is distributable.
  11904.  
  11905. Note that people with SGI machines *can* use jpeg: there is a module
  11906. with the same interface that uses the sgi compression library to
  11907. compress/decompress jpeg images.
  11908.  
  11909. --
  11910. Jack Jansen        | If I can't dance I don't want to be part of
  11911. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  11912. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  11913. 
  11914. 
  11915. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  11916.     id AA16569 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 14:13:16 +0200
  11917. Received: by voorn.cwi.nl with SMTP
  11918.     id AA21400 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 14:13:14 +0200
  11919. Message-Id: <9307301213.AA21400=guido@voorn.cwi.nl>
  11920. To: python-list@cwi.nl
  11921. Subject: stdwin 0.9.8 released
  11922. From: Guido.van.Rossum@cwi.nl
  11923. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  11924. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  11925. Date: Fri, 30 Jul 1993 14:13:14 +0200
  11926. Sender: Guido.van.Rossum@cwi.nl
  11927.  
  11928. Well, it only took me 30 minutes to prepare a stdwin distribution that
  11929. will actually work with the stdwinmodule.c from the Python 0.9.9
  11930. release.  It can be picked up from the usual place:
  11931.  
  11932.     ftp.cwi.nl:/pub/stdwin/stdwin0.9.8.tar.Z
  11933.  
  11934. Documentation is lacking as usual -- read stdwin.h and the source...
  11935.  
  11936. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  11937. 
  11938. 
  11939. Replied: Fri, 30 Jul 1993 20:34:57 +0200
  11940. Replied: "Jaap Vermeulen <jaap@sequent.com> python-list@cwi.nl"
  11941. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  11942.     id AA29581 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 18:49:30 +0200
  11943. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  11944.     id AA13017; Fri, 30 Jul 93 09:46:13 -0700
  11945. Received: by eng2.sequent.com (5.65/1.34)
  11946.     id AA09281; Fri, 30 Jul 93 09:49:16 -0700
  11947. Message-Id: <9307301649.AA09281@eng2.sequent.com>
  11948. To: Guido.van.Rossum@cwi.nl
  11949. Cc: python-list@cwi.nl
  11950. Subject: Re: Why does only sgi have DO_PG in posixmodule.c
  11951. Priority: Normal
  11952. Precedence: first-class
  11953. Organization: Sequent Computer Systems, Inc.
  11954.           Service Technology - MailStop: WIL2-610
  11955.           15450 S.W. Koll Parkway
  11956.           Beaverton, OR  97006-6063
  11957. X-Phone: (503) 578-4404
  11958. X-Fax: (503) 578-4540
  11959. X-Uucp: ...!uunet!sequent!jaap
  11960. X-Internet: jaap@sequent.com
  11961. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  11962.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  11963.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  11964. In-Reply-To: Guido.van.Rossum@cwi.nl's message of Fri, 30 Jul 1993 10:23:20 +0200.
  11965.              <9307300823.AA18847=guido@voorn.cwi.nl> 
  11966. Date: Fri, 30 Jul 1993 09:49:15 -0700
  11967. From: Jaap Vermeulen <jaap@sequent.com>
  11968.  
  11969.  
  11970. | There is some output to stderr, but only if the interpreter gets
  11971. | seriously confused.  Stack traces go to whatever sys.stderr points to.
  11972.  
  11973. What about stderr output from posix.system() or posix.popen()?
  11974.  
  11975.     -Jaap-
  11976. --
  11977. Jaap Vermeulen                    +--------------------------+
  11978.                         | Sequent Computer Systems |
  11979.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  11980.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  11981. 
  11982. 
  11983. Replied: Fri, 30 Jul 1993 20:32:50 +0200
  11984. Replied: "Jaap Vermeulen <jaap@sequent.com> "
  11985. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  11986.     id AA29685 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 18:52:16 +0200
  11987. Received: from eng2.sequent.com by gateway.sequent.com (5.61/1.34)
  11988.     id AA13103; Fri, 30 Jul 93 09:49:03 -0700
  11989. Received: by eng2.sequent.com (5.65/1.34)
  11990.     id AA09689; Fri, 30 Jul 93 09:52:06 -0700
  11991. Message-Id: <9307301652.AA09689@eng2.sequent.com>
  11992. To: Fraser@europarc.xerox.com
  11993. Cc: python-list@cwi.nl
  11994. Subject: Re: Bitmaps
  11995. Priority: Normal
  11996. Precedence: first-class
  11997. Organization: Sequent Computer Systems, Inc.
  11998.           Service Technology - MailStop: WIL2-610
  11999.           15450 S.W. Koll Parkway
  12000.           Beaverton, OR  97006-6063
  12001. X-Phone: (503) 578-4404
  12002. X-Fax: (503) 578-4540
  12003. X-Uucp: ...!uunet!sequent!jaap
  12004. X-Internet: jaap@sequent.com
  12005. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  12006.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  12007.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  12008. In-Reply-To: Fraser@europarc.xerox.com's message of Fri, 30 Jul 1993 01:47:09 -0700.
  12009.              <199307300847.AA07971@eros.EuroPARC.Xerox.COM> 
  12010. Date: Fri, 30 Jul 1993 09:52:05 -0700
  12011. From: Jaap Vermeulen <jaap@sequent.com>
  12012.  
  12013.  
  12014. | Talking of Guido, if, like me, you haven't met him and wonder what he
  12015. | looks like, tell xmosaic to open the CWI home page, which I found at
  12016.  
  12017. Who the hell want to know what Guido looks like (with his colorful
  12018. glasses)!!! :-) :-) :-) :-) :-) :-) :-)
  12019.  
  12020.     -Jaap-
  12021. --
  12022. Jaap Vermeulen                    +--------------------------+
  12023.                         | Sequent Computer Systems |
  12024.     Internet : jaap@sequent.com        | Beaverton, Oregon       |
  12025.     Uucp     : ...uunet!sequent!jaap    +--------------------------+
  12026. 
  12027. 
  12028. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  12029.     id AA04181 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 20:34:58 +0200
  12030. Received: by voorn.cwi.nl with SMTP
  12031.     id AA23285 (5.65b/3.8/CWI-Amsterdam); Fri, 30 Jul 1993 20:34:58 +0200
  12032. Message-Id: <9307301834.AA23285=guido@voorn.cwi.nl>
  12033. To: Jaap Vermeulen <jaap@sequent.com>
  12034. Cc: python-list@cwi.nl
  12035. Subject: Re: Why does only sgi have DO_PG in posixmodule.c 
  12036. In-Reply-To: Your message of "Fri, 30 Jul 1993 09:49:15 MDT."
  12037.              <9307301649.AA09281@eng2.sequent.com> 
  12038. From: Guido.van.Rossum@cwi.nl
  12039. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  12040. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  12041. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  12042. Date: Fri, 30 Jul 1993 20:34:57 +0200
  12043. Sender: Guido.van.Rossum@cwi.nl
  12044.  
  12045. > | There is some output to stderr, but only if the interpreter gets
  12046. > | seriously confused.  Stack traces go to whatever sys.stderr points to.
  12047. > What about stderr output from posix.system() or posix.popen()?
  12048.  
  12049. Good question.  Note that you can now use os.dup(), os.open(),
  12050. os.close() etc. to manipulate file descriptors, so in principle it is
  12051. possible, but I agree that fd's 0, 1, 2 should inherit from
  12052. sys.stdin/out/err.
  12053.  
  12054. (I'm afraid this addition never made the NEWS file...  Check the
  12055. ChangeLog file however; it's also in the library manual!)
  12056.  
  12057. Next release, hopefully!
  12058.  
  12059. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  12060. 
  12061. 
  12062. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  12063.     id AA23163 (5.65b/3.8/CWI-Amsterdam); Sat, 31 Jul 1993 01:59:59 +0200
  12064. To: Guido.van.Rossum@cwi.nl
  12065. Cc: jaap@sequent.com, python-list@cwi.nl
  12066. In-Reply-To: <9307301834.AA23285=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  12067. Subject: Re: Why does only sgi have DO_PG in posixmodule.c 
  12068. Date: Fri, 30 Jul 93 16:58:54 PDT
  12069. From: lance@markv.com
  12070. Sender: lance@markv.com
  12071. Message-Id:  <9307301658.aa10696@hermix.markv.com>
  12072. Source-Info:  From (or Sender) name not authenticated.
  12073.  
  12074.  
  12075. setting DO_PG for SCO ODT 2.0 works fine!
  12076. Just wanted to let people know..
  12077.  
  12078. --
  12079.  
  12080. Lance Ellinghouse           lance@markv.com
  12081.  
  12082. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  12083. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  12084. You can recieve my Public Key by `finger lance@mark.com`
  12085. 
  12086. 
  12087. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  12088.     id AA24264 (5.65b/3.8/CWI-Amsterdam); Sat, 31 Jul 1993 02:09:51 +0200
  12089. To: python-list@cwi.nl
  12090. Subject: replacement for nntpxmit.py
  12091. Date: Fri, 30 Jul 93 17:08:51 PDT
  12092. From: lance@markv.com
  12093. Sender: lance@markv.com
  12094. Message-Id:  <9307301708.aa10911@hermix.markv.com>
  12095. Source-Info:  From (or Sender) name not authenticated.
  12096.  
  12097.  
  12098. I got completely tired of nntpxmit dieing on my system so I thought
  12099. I would rewrite it in Python.. Thanks to the new nntplib.py file in the
  12100. 0.9.9 lib directory I was able to toss out about 200 lines of code that
  12101. I had written and now have a nntpxmit.py file that works!! 
  12102. Here it is for any who wish it.. please let me know of any bugs or 
  12103. improvements.. 
  12104. Mind you there are almost NO comments in it.. have not had time to go 
  12105. through it and probably won't have time now that it is working..
  12106.  
  12107. #! /usr2/local/bin/python
  12108.  
  12109. # This file reads the batch files created by NNTP and 
  12110. # sends the messages to the remote site.
  12111.  
  12112. # The usage for this program is:  
  12113. #
  12114. # nntpxmit Batch_dir News_dir
  12115.  
  12116. import sys
  12117. import strop
  12118. import posix
  12119. from nntplib import NNTP, error_temp, error_reply
  12120.  
  12121. False = 0
  12122. True  = 1
  12123.  
  12124. #####
  12125. # Global locations to use
  12126. #####
  12127. NewsSpoolDir = ''
  12128. NewsBatchDir = ''
  12129. if len(sys.argv) != 3:
  12130.     print 'Usage: ' + sys.argv[0] + ' NNTP_Batch_Dir NEWS_Directory'
  12131.     raise SystemExit
  12132. NewsSpoolDir = sys.argv[2] + '/'
  12133. NewsBatchDir = sys.argv[1] + '/'
  12134. NewsBatchHost= ''
  12135.  
  12136. #####
  12137. # Codes returned from NNTP Server
  12138. #####
  12139. OK_NOPOST    = 201
  12140. OK_CANPOST   = 200
  12141. OK_XFERD     = 235
  12142. CONT_XFER    = 335
  12143. ERR_GOTIT    = 435
  12144. ERR_XFERRJCT = 437
  12145. ERR_XFERFAIL = 436
  12146.  
  12147. #####
  12148. # Globals
  12149. #####
  12150. # Transfer Stats
  12151. Stats = {
  12152.     'offered':0,
  12153.     'accepted':0,
  12154.     'rejected':0,
  12155.     'failed':0
  12156.     }
  12157.     
  12158. Debug = False
  12159. Report_Stats = True
  12160. ReQueue_fails = True
  12161.  
  12162. Debug_Stream = None
  12163.  
  12164. Requeue_Article_lst = []
  12165.  
  12166. #####
  12167. # Support Functions
  12168. #####
  12169.  
  12170. def reset_stats():
  12171.         global Stats
  12172.         Stats['offered']  = 0
  12173.         Stats['accepted'] = 0
  12174.         Stats['rejected'] = 0
  12175.         Stats['failed']   = 0
  12176.         return None
  12177.  
  12178. def print_stats(host):
  12179.         global Stats
  12180.         print ''
  12181.         print 'Statistics for \'' + host + '\''
  12182.         print '='*30
  12183.         print 'Offered  : ' + `Stats['offered']`
  12184.         print 'Accepted : ' + `Stats['accepted']`
  12185.         print 'Rejected : ' + `Stats['rejected']`
  12186.         print 'Failed   : ' + `Stats['failed']`
  12187.         print ''
  12188.         return None
  12189.  
  12190. def write_requeue(file_name, lst):
  12191.     try:
  12192.         fp = open(NewsBatchDir + file_name,'a+')
  12193.     except IOError, msg:
  12194.         print 'write_requeue(' + NewsBatchDir + file_name + ') failed: ' + msg
  12195.         return None
  12196.     if len(lst) == 0:
  12197.         fp.close()
  12198.         return None
  12199.     for item in lst:
  12200.         try:
  12201.             fp.write(item[0] + ' ' + item[1] + '\n')
  12202.         except IOError, msg:
  12203.             print 'write_requeue(' + NewsBatchDir + file_name + ') failed: ' + msg
  12204.             return None
  12205.     return None
  12206.  
  12207. # This routine takes a file name and loads all the lines in the file
  12208. # into a list. This list contains 2 parts, ('filename','message id')
  12209. # This information is taked from a batch file
  12210. def load_batch(file_name):
  12211.     try:
  12212.         fp = open(file_name,'r')
  12213.     except:
  12214.         return None
  12215.     list = []
  12216.     list = fp.readlines()
  12217.     for ndx in range(len(list)):
  12218.         list_el = strop.strip(list[ndx])
  12219.         l = len(list_el)
  12220.         j = 0
  12221.         while j < l and list_el[j] != ' ':
  12222.             j = j + 1
  12223.         fn = list_el[0:j]
  12224.         msgid = list_el[j:]
  12225.         list[ndx] = (strop.strip(fn),strop.strip(msgid))
  12226.     try:
  12227.         t = posix.unlink(file_name)
  12228.     except:
  12229.         pass
  12230.     return list
  12231.  
  12232. # this will lock a directory
  12233. def lock_dir(dir_to_lock):
  12234.     t_dir = posix.getcwd()
  12235.     r = posix.chdir(dir_to_lock)
  12236.     try:
  12237.         r = open('.LCK'+`posix.getpid()`,'w')
  12238.     except:
  12239.         r = posix.chdir(t_dir)
  12240.         return False
  12241.     r.close()
  12242.     try:
  12243.         r = posix.link('.LCK'+`posix.getpid()`,'.LCKdir')
  12244.     except:
  12245.         r = posix.chdir(t_dir)
  12246.         return False
  12247.     r = posix.chdir(t_dir)
  12248.     return True
  12249.  
  12250. # This will unlock the directory
  12251. def unlock_dir(dir_to_unlock):
  12252.     t_dir = posix.getcwd()
  12253.     r = posix.chdir(dir_to_unlock)
  12254.     try:
  12255.         r = posix.unlink('.LCKdir')
  12256.         r = posix.unlink('.LCK'+`posix.getpid()`)
  12257.     except:
  12258.         return False
  12259.     r = posix.chdir(t_dir)
  12260.     return True
  12261.  
  12262. # This function returns 2 lists.. 
  12263. # 1: A list of all files in the directory that are NOT requeue files (! '~xxx')
  12264. # 2: A list of all files in the directory that are requeue files (~xxx)
  12265. # This function NEVER returns files that start as '.LCK' as these
  12266. # are lock files and Never need to be touched and it never returns
  12267. # files that start with '.' as these are hidden
  12268. def rtn_dirlist(dir_to_list):
  12269.     requeue_lst = []
  12270.     rtn_lst = []
  12271.     try:
  12272.         lst = posix.listdir(dir_to_list)
  12273.     except:
  12274.         return (None, None)
  12275.     for i in range(len(lst)):
  12276.         name = lst[i]
  12277.         if name[0] == '.':
  12278.             continue
  12279.         if name[0] == '~':
  12280.             r = requeue_lst.append(name)
  12281.             continue
  12282.         rtn_lst.append(name)
  12283.     return (rtn_lst, requeue_lst)
  12284.  
  12285. def process_file(f_name):
  12286.     global Requeue_Article_lst
  12287.     count = -1
  12288.     lst = load_batch(NewsBatchDir + f_name)
  12289.     if len(lst):
  12290.         reset_stats()
  12291.         try:
  12292.             if f_name[0] == '~':
  12293.                 host = f_name[1:]
  12294.             else:
  12295.                 host = f_name
  12296.             n = NNTP().init(host)
  12297.             print 'NNTP welcomes with \'' + n.getwelcome() + '\''
  12298.         except error_temp, msg:
  12299.             print 'NNTP connect failed: ' + msg
  12300.             for item in lst:
  12301.                 Requeue_Article_lst.append(item)
  12302.             return None
  12303.         for item in lst:
  12304.             count = count + 1
  12305.             try:
  12306.                 f = open(NewsSpoolDir + item[0],'r')
  12307.             except IOError:
  12308.                 print 'opening of ' + NewsSpoolDir + item[0],
  12309.                 print ' failed: ' + msg
  12310.                 Stats['failed'] = Stats['failed'] + 1
  12311.                 continue
  12312.             try:
  12313.                 Stats['offered'] = Stats['offered'] + 1
  12314.                 rtn = n.ihave(item[1],f)
  12315.                 Stats['accepted'] = Stats['accepted'] + 1
  12316.             except error_temp,msg:
  12317.                 rtn_val = eval(msg[:3])
  12318.                 if rtn_val == ERR_XFERFAIL:
  12319.                     print 'Transfer failed: Requeuing ' + item[1]
  12320.                     Requeue_Article_lst.append(item)
  12321.                     Stats['failed'] = Stats['failed'] + 1
  12322.                 if rtn_val == ERR_GOTIT:
  12323.                     Stats['rejected'] = Stats['rejected'] + 1
  12324.             except EOFError, msg:
  12325.                 print 'Connection Closed!! requeueing items left'
  12326.                 print 'Returned: ' + msg
  12327.                 print 'Requeuing ' + `eval(len(lst) - count)` + ' items.'
  12328.                 for items in lst[count:]:
  12329.                     Requeue_Article_lst.append(items)
  12330.                 return None
  12331.     n.quit()
  12332.     print_stats(host)
  12333.     return None
  12334.  
  12335. # This is the main routine that runs everything
  12336. def main():
  12337.     global Stats
  12338.     global Requeue_Article_lst
  12339.     if not lock_dir(NewsBatchDir):
  12340.         print 'Could not lock \'' + NewsBatchDir + '\'.'
  12341.         print 'Try again later.'
  12342.         raise SystemExit
  12343.     do_list, redo_list = rtn_dirlist(NewsBatchDir)
  12344.     if redo_list != None and len(redo_list):
  12345.         for f_name in redo_list:
  12346.             process_file(f_name)
  12347.             if len(Requeue_Article_lst):
  12348.                 write_requeue(f_name,Requeue_Article_lst)
  12349.                 Requeue_Article_lst = []
  12350.     if do_list != None and len(do_list):
  12351.         for f_name in do_list:
  12352.             process_file(f_name)
  12353.             if len(Requeue_Article_lst):
  12354.                 write_requeue('~'+f_name,Requeue_Article_lst)
  12355.                 Requeue_Article_lst = []
  12356.     r = unlock_dir(NewsBatchDir)
  12357.     return None
  12358.  
  12359. main()
  12360.  
  12361.  
  12362. --
  12363.  
  12364. Lance Ellinghouse           lance@markv.com
  12365.  
  12366. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  12367. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  12368. You can recieve my Public Key by `finger lance@mark.com`
  12369. 
  12370. 
  12371. Replied: Sun, 01 Aug 1993 14:47:49 +0200
  12372. Replied: "Gerry Stringer <gerry@camscan.co.uk> python-list@cwi.nl"
  12373. Received: from eros.uknet.ac.uk by charon.cwi.nl with SMTP
  12374.     id AA25159 (5.65b/3.8/CWI-Amsterdam); Sun, 1 Aug 1993 02:47:18 +0200
  12375. Received: from camscan.co.uk by eros.uknet.ac.uk with UUCP 
  12376.           id <g.14448-0@eros.uknet.ac.uk>; Sun, 1 Aug 1993 01:46:59 +0100
  12377. Received: from electra.camscan.co.uk by star.camscan.co.uk;
  12378.           Sat, 31 Jul 93 13:23:27 BST
  12379. From: Gerry Stringer <gerry@camscan.co.uk>
  12380. Date: Sat, 31 Jul 93 13:23:31 BST
  12381. Message-Id: <3070.9307311223@electra.camscan.co.uk>
  12382. To: python-list@cwi.nl
  12383. Subject: Re: revised import.c
  12384.  
  12385.  
  12386. >I can see why you'd want this in certain cases, but when I designed
  12387. >this code I made a conscious decision to require that the .py should
  12388. >file be there for the .pyc file to be valid -- unlike Emacs .elc
  12389. >files, .pyc files can be considered as pure caches and are managed
  12390. >completely automatic.  Perhaps Lance's version can be made into a
  12391. >compile-time or run-time option?
  12392.  
  12393. My vote goes for some runtime control in fact, as I've mentioned
  12394. before, I'd actually like to be able to 'compile' Python code and run
  12395. from memory.
  12396.  
  12397. Just a thought.
  12398.  
  12399.     gerry (gerry@camscan.co.uk)
  12400.  
  12401.  
  12402. 
  12403. 
  12404. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  12405.     id AA05793 (5.65b/3.8/CWI-Amsterdam); Sun, 1 Aug 1993 14:47:50 +0200
  12406. Received: by voorn.cwi.nl with SMTP
  12407.     id AA25592 (5.65b/3.8/CWI-Amsterdam); Sun, 1 Aug 1993 14:47:50 +0200
  12408. Message-Id: <9308011247.AA25592=guido@voorn.cwi.nl>
  12409. To: Gerry Stringer <gerry@camscan.co.uk>
  12410. Cc: python-list@cwi.nl
  12411. Subject: Re: revised import.c 
  12412. In-Reply-To: Your message of "Sat, 31 Jul 1993 13:23:31 MDT."
  12413.              <3070.9307311223@electra.camscan.co.uk> 
  12414. From: Guido.van.Rossum@cwi.nl
  12415. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  12416. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  12417. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  12418. Date: Sun, 01 Aug 1993 14:47:49 +0200
  12419. Sender: Guido.van.Rossum@cwi.nl
  12420.  
  12421. > My vote goes for some runtime control in fact, as I've mentioned
  12422. > before, I'd actually like to be able to 'compile' Python code and run
  12423. > from memory.
  12424.  
  12425. Note that you can do this with the new compile() built-in function
  12426. which turns a string into a code object; exec() and eval() will accept
  12427. code objects and run them.  (This was done so I could implement the
  12428. "freeze" script.)
  12429.  
  12430. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  12431. 
  12432. 
  12433. Received: from ELVIS.TAMU.EDU by charon.cwi.nl with SMTP
  12434.     id AA18378 (5.65b/3.8/CWI-Amsterdam); Mon, 2 Aug 1993 19:00:14 +0200
  12435. Received: by elvis.tamu.edu (920330.SGI/920502.SGI.AUTO)
  12436.     for python-list@cwi.nl id AA29763; Mon, 2 Aug 93 11:58:09 -0500
  12437. Date: Mon, 2 Aug 93 11:58:09 -0500
  12438. From: allan@elvis.tamu.edu (Allan Bailey)
  12439. Message-Id: <9308021658.AA29763@elvis.tamu.edu>
  12440. To: python-list@cwi.nl
  12441. Subject: MD5 problem in 0.9.9
  12442.  
  12443.  
  12444.   I'm trying to compile the md5 stuff into python.  
  12445.  
  12446.   I had to modify the md5 code from rsa.com to agree with the
  12447. python code, but it seems to compile.  When I run the demo though
  12448. I get the following
  12449.  
  12450. ---begin:
  12451. [~/python/python/demo/md5test]$ ./md5driver.py -x
  12452. MD5 test suite results:
  12453. XXX lineno: 62, opcode: 212
  12454. Stack backtrace (innermost last):
  12455.   File "./md5driver.py", line 127
  12456.     main()
  12457.   File "./md5driver.py", line 123
  12458.     MDTestSuite()
  12459.   File "./md5driver.py", line 97
  12460.     MDString('')
  12461.   File "./md5driver.py", line 62
  12462.     MDPrint(md5(str).digest())
  12463. SystemError: eval_code: unknown opcode
  12464.  
  12465. ---end:
  12466.  
  12467.   Any help would be appreciated.
  12468.  
  12469. -- 
  12470. Allan Bailey, UNIX programmer, CSC          | "Freedom is not free."
  12471. Infinite Diversity in Infinite Combinations | or: allan.bailey@tamu.edu
  12472.  
  12473. 
  12474. 
  12475. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  12476.     id AA20258 (5.65b/3.8/CWI-Amsterdam); Mon, 2 Aug 1993 19:57:57 +0200
  12477. To: python-list@cwi.nl
  12478. Subject: XmNlabelString errors....
  12479. X-Organization: Mark V Systems Ltd.
  12480. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  12481. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  12482. Date: Mon, 2 Aug 93 10:57:43 PDT
  12483. From: lance@markv.com
  12484. Sender: lance@markv.com
  12485. Message-Id:  <9308021057.aa21740@hermix.markv.com>
  12486. Source-Info:  From (or Sender) name not authenticated.
  12487.  
  12488.  
  12489. I compiled the X11 support into Python 0.9.9 with no problems at all
  12490. on SCO ODT 2.0 (just did not put in the EditRes module info).
  12491. When I run a number of the sample/test programs, I get X errors
  12492. stating that XmNlabelString should be a compound label. I cannot
  12493. see where that is being set up in the code..
  12494.  
  12495. Anyone else see this?
  12496. Anything I can do?
  12497.  
  12498. --
  12499.  
  12500. Lance Ellinghouse           lance@markv.com
  12501.  
  12502. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  12503. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  12504. You can recieve my Public Key by `finger lance@mark.com`
  12505. 
  12506. 
  12507. Received: from ELVIS.TAMU.EDU by charon.cwi.nl with SMTP
  12508.     id AA05610 (5.65b/3.8/CWI-Amsterdam); Tue, 3 Aug 1993 01:06:10 +0200
  12509. Received: by elvis.tamu.edu (920330.SGI/920502.SGI.AUTO)
  12510.     for python-list@cwi.nl id AA04977; Mon, 2 Aug 93 18:05:57 -0500
  12511. Date: Mon, 2 Aug 93 18:05:57 -0500
  12512. From: allan@elvis.tamu.edu (Allan Bailey)
  12513. Message-Id: <9308022305.AA04977@elvis.tamu.edu>
  12514. To: python-list@cwi.nl
  12515. Subject: md5.c: how to compile it in correctly?
  12516.  
  12517.  
  12518. I've gotten the md5.c files from rsa.com, and i've gotten the
  12519. ones from the pgp 2.3a distribution.  The both don't work.
  12520.  
  12521. Has anyone else gotten these to  compile and work?
  12522.  
  12523. I get segmentation faults because of bad pointer or something.
  12524.  
  12525. ideas, hints welcome....
  12526.  
  12527. -- 
  12528. Allan Bailey, UNIX programmer, CSC          | "Freedom is not free."
  12529. Infinite Diversity in Infinite Combinations | or: allan.bailey@tamu.edu
  12530.  
  12531. 
  12532. 
  12533. Received: from ELVIS.TAMU.EDU by charon.cwi.nl with SMTP
  12534.     id AA12587 (5.65b/3.8/CWI-Amsterdam); Tue, 3 Aug 1993 01:36:01 +0200
  12535. Received: by elvis.tamu.edu (920330.SGI/920502.SGI.AUTO)
  12536.     for python-list@cwi.nl id AA05522; Mon, 2 Aug 93 18:35:58 -0500
  12537. Date: Mon, 2 Aug 93 18:35:58 -0500
  12538. From: allan@elvis.tamu.edu (Allan Bailey)
  12539. Message-Id: <9308022335.AA05522@elvis.tamu.edu>
  12540. To: python-list@cwi.nl
  12541. Subject: Re: md5.c: how to compile it in correctly? (never mind...)
  12542.  
  12543.  
  12544. >
  12545. >I've gotten the md5.c files from rsa.com, and i've gotten the
  12546. >ones from the pgp 2.3a distribution.  The both don't work.
  12547. >
  12548. >Has anyone else gotten these to  compile and work?
  12549. >
  12550. >I get segmentation faults because of bad pointer or something.
  12551. >
  12552. >ideas, hints welcome....
  12553. >
  12554.  
  12555.   a few minutes after i sent this i took another look at the 
  12556. md5 code from rsa, and the md5module.c and realized that
  12557. the &mdContext should be the 2nd arg and mdContext.digest should
  12558. be the 1st.
  12559.  
  12560.  works spiffy now.  sorry to bother y'all, but i'm just
  12561. a beginner with this.
  12562.  
  12563. -- 
  12564. Allan Bailey, UNIX programmer, CSC          | "Freedom is not free."
  12565. Infinite Diversity in Infinite Combinations | or: allan.bailey@tamu.edu
  12566.  
  12567. 
  12568. 
  12569. Received: from ELVIS.TAMU.EDU by charon.cwi.nl with SMTP
  12570.     id AA19262 (5.65b/3.8/CWI-Amsterdam); Tue, 3 Aug 1993 02:32:06 +0200
  12571. Received: by elvis.tamu.edu (920330.SGI/920502.SGI.AUTO)
  12572.     for python-list@cwi.nl id AA06014; Mon, 2 Aug 93 19:11:46 -0500
  12573. Date: Mon, 2 Aug 93 19:11:46 -0500
  12574. From: allan@elvis.tamu.edu (Allan Bailey)
  12575. Message-Id: <9308030011.AA06014@elvis.tamu.edu>
  12576. To: python-list@cwi.nl
  12577. Subject: python and linux
  12578.  
  12579.  
  12580.   Just a success note for Guido and the list:
  12581.  
  12582.   python 0.9.9, stdwin, readline, gmp, and md5 all go up on
  12583. linux 0.99 pl11 with out much problems.
  12584.  
  12585.   If anyone is having problems trying to get python on their
  12586. linux box compiled let me know and I'll help.
  12587.  
  12588. -- 
  12589. Allan Bailey, UNIX programmer, CSC          | "Freedom is not free."
  12590. Infinite Diversity in Infinite Combinations | or: allan.bailey@tamu.edu
  12591.  
  12592. 
  12593. 
  12594. Received: from ent-img.ent-img.com by charon.cwi.nl with SMTP
  12595.     id AA09169 (5.65b/3.8/CWI-Amsterdam); Tue, 3 Aug 1993 01:22:14 +0200
  12596. Received: from overlord.ent-img.com by gatekeeper.ent-img.com with smtp
  12597.     (Smail3.1.26.7 #4) id m0oN9Ch-0006qRC; Mon, 2 Aug 93 16:22 PDT
  12598. Received: by overlord.ent-img.com (920330.SGI/920502.SGI)
  12599.     for @gatekeeper.ent-img.com:python-list@cwi.nl id AA06488; Mon, 2 Aug 93 16:22:06 -0700
  12600. From: kevin@overlord.ent-img.com (Kevin Gage)
  12601. Message-Id: <9308022322.AA06488@overlord.ent-img.com>
  12602. Subject: SGI compile
  12603. To: python-list@cwi.nl
  12604. Date: Mon, 2 Aug 1993 16:22:06 -0800 (PDT)
  12605. X-Mailer: ELM [version 2.4 PL21]
  12606. Mime-Version: 1.0
  12607. Content-Type: text/plain; charset=US-ASCII
  12608. Content-Transfer-Encoding: 7bit
  12609. Content-Length: 348       
  12610.  
  12611. I'm on a Indigo R3k and trying the basic compile.
  12612.  
  12613. I've uncommented SYSVDEF=-DSYSV ,but I'm still getting
  12614. an error:
  12615.  
  12616. socketmodule.c:79: sys/socket.h: No such file or directory
  12617. socketmodule.c:81: sys/un.h: No such file or directory
  12618. *** Error code 1
  12619.  
  12620. Stop.
  12621.  
  12622. Any help would be appreciated.
  12623.  
  12624. Kevin D. Gage
  12625.  
  12626. CST Entertainment Imaging Inc.
  12627. Los Angeles
  12628.  
  12629.  
  12630.  
  12631. 
  12632. 
  12633. Received: from helios.ath.epa.gov by charon.cwi.nl with SMTP
  12634.     id AA12615 (5.65b/3.8/CWI-Amsterdam); Tue, 3 Aug 1993 21:12:06 +0200
  12635. Received: by helios.ath.epa.gov (5.65c+/1.34)
  12636.     id AA09155; Tue, 3 Aug 1993 15:12:02 -0400
  12637. Date: Tue, 3 Aug 1993 15:12:02 -0400
  12638. From: Kevin Weinrich <kbw@helios.ath.epa.gov>
  12639. Message-Id: <199308031912.AA09155@helios.ath.epa.gov>
  12640. To: python-list@cwi.nl
  12641. Subject: How to compile STDWIN on MS-DOS?
  12642.  
  12643. I tried to ask Guido van Rossum this question, but his vacation-mail
  12644. program says he'll be gone for the next 7 weeks.  It said I should
  12645. ask this group in his absence.
  12646.  
  12647. Does anyone know how to compile STDWIN for MS-DOS?  The README file
  12648. said that it could be done, but not how.  All the makefiles seem
  12649. set up for UNIX.  Alternatively, FTP sites where DOS executables
  12650. are archived would help me out.
  12651.  
  12652. Please e-mail any responses to me.  I'm not subscribed to this group.
  12653. ---
  12654. Kevin Weinrich     Atlantic Research Corp. (till August 1)
  12655. kbw@helios.ath.epa.gov
  12656. 
  12657. 
  12658. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  12659.     id AA12488 (5.65b/3.8/CWI-Amsterdam); Wed, 4 Aug 1993 04:11:55 +0200
  12660. To: python-list@cwi.nl
  12661. Subject: md5 source
  12662. X-Organization: Mark V Systems Ltd.
  12663. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  12664. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  12665. Date: Tue, 3 Aug 93 19:11:08 PDT
  12666. From: lance@markv.com
  12667. Sender: lance@markv.com
  12668. Message-Id:  <9308031911.aa02342@hermix.markv.com>
  12669. Source-Info:  From (or Sender) name not authenticated.
  12670.  
  12671. Can someone send me the md5 source that WORKS with python 0.9.9's
  12672. md5module.c??? the MD5_CNTX structure does not seem to be
  12673. compatible... 
  12674.  
  12675. Please don't tell me where to get it, just send me the files PLEASE!
  12676. (unless it is on a FTP site, and the code WILL work)
  12677.  
  12678. Thank you!!!
  12679.  
  12680. --
  12681.  
  12682. Lance Ellinghouse           lance@markv.com
  12683.  
  12684. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  12685. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  12686. You can recieve my Public Key by `finger lance@mark.com`
  12687. 
  12688. 
  12689. Received: from ansjovis.cwi.nl by charon.cwi.nl with SMTP
  12690.     id AA24291 (5.65b/3.8/CWI-Amsterdam); Wed, 4 Aug 1993 09:41:28 +0200
  12691. Received: by ansjovis.cwi.nl with SMTP
  12692.     id AA10816 (5.65b/3.8/CWI-Amsterdam); Wed, 4 Aug 1993 09:41:28 +0200
  12693. Message-Id: <9308040741.AA10816=sjoerd@ansjovis.cwi.nl>
  12694. To: lance@markv.com
  12695. Cc: python-list@cwi.nl
  12696. Subject: Re: md5 source 
  12697. In-Reply-To: Your message of Tue, 03 Aug 1993 19:11:08 -0700.
  12698.              <9308031911.aa02342@hermix.markv.com> 
  12699. Date: Wed, 04 Aug 1993 09:41:27 +0200
  12700. From: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
  12701.  
  12702. On Tue, Aug 3 1993 lance@markv.com wrote:
  12703.  
  12704. > Can someone send me the md5 source that WORKS with python 0.9.9's
  12705. > md5module.c??? the MD5_CNTX structure does not seem to be
  12706. > compatible... 
  12707. > Please don't tell me where to get it, just send me the files PLEASE!
  12708. > (unless it is on a FTP site, and the code WILL work)
  12709.  
  12710. I have put a copy of our version of md5 on ftp.cwi.nl in directory
  12711. /pub/md5.  It is the version we use at CWI, so I think it will work
  12712. with python.
  12713.  
  12714. Sjoerd Mullender
  12715. CWI, dept. CST, Kruislaan 413, 1098 SJ Amsterdam, Netherlands
  12716. email: Sjoerd.Mullender@cwi.nl        fax:   +31 20 592 4199
  12717. phone: +31 20 592 4127            telex: 12571 mactr nl
  12718. 
  12719. 
  12720. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  12721.     id AA29736 (5.65b/3.8/CWI-Amsterdam); Wed, 4 Aug 1993 17:49:31 +0200
  12722. To: Sjoerd.Mullender@cwi.nl
  12723. Cc: python-list@cwi.nl
  12724. In-Reply-To: <9308040741.AA10816=sjoerd@ansjovis.cwi.nl> (message from Sjoerd Mullender on Wed, 04 Aug 1993 09:41:27 +0200)
  12725. Subject: Re: md5 source 
  12726. X-Organization: Mark V Systems Ltd.
  12727. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  12728. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  12729. Date: Wed, 4 Aug 93 8:48:35 PDT
  12730. From: lance@markv.com
  12731. Sender: lance@markv.com
  12732. Message-Id:  <9308040848.aa14987@hermix.markv.com>
  12733. Source-Info:  From (or Sender) name not authenticated.
  12734.  
  12735.  > On Tue, Aug 3 1993 lance@markv.com wrote:
  12736.  > 
  12737.  > > Can someone send me the md5 source that WORKS with python 0.9.9's
  12738.  > > md5module.c??? the MD5_CNTX structure does not seem to be
  12739.  > > compatible... 
  12740.  > > 
  12741.  > > Please don't tell me where to get it, just send me the files PLEASE!
  12742.  > > (unless it is on a FTP site, and the code WILL work)
  12743.  > 
  12744.  > I have put a copy of our version of md5 on ftp.cwi.nl in directory
  12745.  > /pub/md5.  It is the version we use at CWI, so I think it will work
  12746.  > with python.
  12747.  > 
  12748.  
  12749. Great!!!!
  12750. Thank you very much!!
  12751.  
  12752. --
  12753.  
  12754. Lance Ellinghouse           lance@markv.com
  12755.  
  12756. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  12757. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  12758. You can recieve my Public Key by `finger lance@mark.com`
  12759. 
  12760. 
  12761. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  12762.     id AA13335 (5.65b/3.9/CWI-Amsterdam); Fri, 6 Aug 1993 20:05:16 +0200
  12763. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11905>; Fri, 6 Aug 1993 11:04:54 PDT
  12764. Received: by eros.EuroPARC.Xerox.COM with SMTP
  12765.     (5.65c/IDA-1.2.9) id AA00161; Fri, 6 Aug 1993 19:04:27 +0100
  12766. Message-Id: <199308061804.AA00161@eros.EuroPARC.Xerox.COM>
  12767. To: python-list@cwi.nl
  12768. Subject: bug in sorting?
  12769. Date:     Fri, 6 Aug 1993 11:04:24 PDT
  12770. From: Fraser@europarc.xerox.com
  12771.  
  12772.  
  12773. The following little program causes my python to core dump with a bus
  12774. error.  Could others try it and see if it does the same?  As far as I
  12775. can see, the objects passed to the compare function are corrupted in
  12776. some way and the first operation on either one causes a crash.  It
  12777. doesn't do it with 0.9.8. I've had a brief browse with my debugger but
  12778. without much luck.
  12779.  
  12780. Ta,
  12781. Quentin
  12782.  
  12783. --------------
  12784.  
  12785. #! /usr/local/bin/python
  12786.     
  12787. def compare(l1,l2):
  12788.    if l1 < l2:
  12789.       return -1
  12790.    if l1 > l2:
  12791.       return 1
  12792.    return 0
  12793.  
  12794. names = ['joe', 'fred', 'peter']
  12795. names.sort(compare)
  12796.  
  12797. for i in names:
  12798.    print i
  12799.  
  12800.  
  12801.  
  12802. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  12803. Quentin Stafford-Fraser                        Tel:  +44 223 341521             
  12804. Rank Xerox EuroPARC,                           Fax:  +44 223 341510     
  12805. 61 Regent Street,                              Home: +44 223 324451
  12806. Cambridge, CB2 1AB
  12807. United Kingdom                                 Fraser@europarc.xerox.com 
  12808.  
  12809.  
  12810.  
  12811. 
  12812. 
  12813. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  12814.     id AA15904 (5.65b/3.9/CWI-Amsterdam); Fri, 6 Aug 1993 21:41:14 +0200
  12815. Received: from eng1.sequent.com by gateway.sequent.com (5.61/1.34)
  12816.     id AA16149; Fri, 6 Aug 93 12:37:56 -0700
  12817. Received: by eng1.sequent.com (5.65/crg/11)
  12818.     id AA19081; Fri, 6 Aug 93 12:39:18 -0700
  12819. Message-Id: <9308061939.AA19081@eng1.sequent.com>
  12820. To: Fraser@europarc.xerox.com
  12821. Cc: python-list@cwi.nl
  12822. Subject: Re: bug in sorting?
  12823. Priority: Normal
  12824. Precedence: first-class
  12825. Organization: Sequent Computer Systems, Inc.
  12826.           Service Technology - MailStop: WIL2-610
  12827.           15450 S.W. Koll Parkway
  12828.           Beaverton, OR  97006-6063
  12829. X-Phone: (503) 578-4404
  12830. X-Fax: (503) 578-4540
  12831. X-Uucp: ...!uunet!sequent!jaap
  12832. X-Internet: jaap@sequent.com
  12833. X-Face: C4Cnai$>Eja5I6Vq?(gdN#SXX#`-XgAnmUn&e54sx7@1>q@vkrd_XnH![P>w.:7IJJ;{Bts
  12834.  WJd)u&G!V}0OR?2o5cUgIY}.T{g]PMC=*~]3n_t)S-ZkC(WG}3:#hcA6Oazx:}yc&k,hsF7D},7x>l
  12835.  nyfRjO7$@]fHBN>aC9-M3pKfbYHiy!PWD{_bx~fo})b4tU.;Ao%x[upCI,
  12836. In-Reply-To: Fraser@europarc.xerox.com's message of Fri, 06 Aug 1993 11:04:24 -0700.
  12837.              <199308061804.AA00161@eros.EuroPARC.Xerox.COM> 
  12838. Date: Fri, 06 Aug 1993 12:39:18 -0700
  12839. From: Jaap Vermeulen <jaap@sequent.com>
  12840.  
  12841.  
  12842. | The following little program causes my python to core dump with a bus
  12843. | error.  Could others try it and see if it does the same?  As far as I
  12844. | can see, the objects passed to the compare function are corrupted in
  12845. | some way and the first operation on either one causes a crash.  It
  12846. | doesn't do it with 0.9.8. I've had a brief browse with my debugger but
  12847. | without much luck.
  12848.  
  12849. After staring at it a little, I figured it out.  It should be passing
  12850. (object *) to mkvalue(), not (object **) in listobject.c:cmp().
  12851. Here's the patch:
  12852.  
  12853. *** listobject.c.Save    Thu Jul 29 01:25:08 1993
  12854. --- listobject.c    Fri Aug  6 12:33:24 1993
  12855. ***************
  12856. *** 520,526
  12857.           return cmpobject(* (object **) v, * (object **) w);
  12858.   
  12859.       /* Call the user-supplied comparison function */
  12860. !     t = mkvalue("OO", v, w);
  12861.       if (t == NULL)
  12862.           return 0;
  12863.       res = call_object(cmpfunc, t);
  12864.  
  12865. --- 520,526 -----
  12866.           return cmpobject(* (object **) v, * (object **) w);
  12867.   
  12868.       /* Call the user-supplied comparison function */
  12869. !     t = mkvalue("OO", * (object **) v, * (object **) w);
  12870.       if (t == NULL)
  12871.           return 0;
  12872.       res = call_object(cmpfunc, t);
  12873.  
  12874. Have fun,
  12875.  
  12876.     -Jaap-
  12877. 
  12878. 
  12879. Received: from nic.eunet.no by charon.cwi.nl with SMTP
  12880.     id AA18842 (5.65b/3.9/CWI-Amsterdam); Tue, 10 Aug 1993 13:46:01 +0200
  12881. Received: from dms.corena.no by Norway.EU.net with UUCP id AA20475
  12882.   (5.65c8/IDA-1.4.4/EUnet/NO for python-list@cwi.nl); Tue, 10 Aug 1993 13:45:54 +0200
  12883. Received: from canis by dms.corena.no (AIX 3.2/UCB 5.64/4.03)
  12884.           id AA44304; Tue, 10 Aug 1993 13:42:54 +0200
  12885. Received: from tropical by nis.corena.no (AIX 3.2/UCB 5.64/4.03)
  12886.           id AA27701; Tue, 10 Aug 1993 13:42:31 +0200
  12887. Received: by tropical (AIX 3.2/UCB 5.64/4.03)
  12888.           id AA49895; Tue, 10 Aug 1993 13:41:06 +0200
  12889. Date: Tue, 10 Aug 1993 13:41:06 +0200
  12890. From: lars@dms.corena.no (Lars Tafjord)
  12891. Message-Id: <9308101141.AA49895@tropical>
  12892. To: python-list@cwi.nl
  12893. Subject: INCREF & DECREF
  12894.  
  12895.  
  12896. Hi!
  12897.  
  12898. I am still a newcomer to Python and have a few annoying core-dump
  12899. problems.  Could someone give some hints on _why_ and _how_ I should
  12900. use INCREF, DECREF, XDECREF and any other related functions/macros?
  12901.  
  12902.  
  12903. ---------------------------------------------------------------
  12904. Lars Tafjord
  12905. Corena A/S, N-1370 ASKER
  12906. NORWAY
  12907. lars@corena.no                    +47 66 79 45 00
  12908. ---------------------------------------------------------------
  12909. 
  12910. 
  12911. Received: from ansjovis.cwi.nl by charon.cwi.nl with SMTP
  12912.     id AA20285 (5.65b/3.9/CWI-Amsterdam); Tue, 10 Aug 1993 14:53:42 +0200
  12913. Received: by ansjovis.cwi.nl with SMTP
  12914.     id AA21444 (5.65b/3.8/CWI-Amsterdam); Tue, 10 Aug 1993 14:53:41 +0200
  12915. Message-Id: <9308101253.AA21444=sjoerd@ansjovis.cwi.nl>
  12916. To: lars@dms.corena.no (Lars Tafjord)
  12917. Cc: python-list@cwi.nl
  12918. Subject: Re: INCREF & DECREF 
  12919. In-Reply-To: Your message of Tue, 10 Aug 1993 13:41:06 +0200.
  12920.              <9308101141.AA49895@tropical> 
  12921. Date: Tue, 10 Aug 1993 14:53:41 +0200
  12922. From: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
  12923.  
  12924. Guido is on vacation, so I'll try to answer your question.  If I am
  12925. wrong somebody will no doubt correct me.
  12926.  
  12927. On Tue, Aug 10 1993 Lars Tafjord wrote:
  12928.  
  12929. > I am still a newcomer to Python and have a few annoying core-dump
  12930. > problems.  Could someone give some hints on _why_ and _how_ I should
  12931. > use INCREF, DECREF, XDECREF and any other related functions/macros?
  12932.  
  12933. Use XINCREF or XDECREF instead of INCREF/DECREF when the argument may
  12934. be NULL.
  12935.  
  12936. The basic idea is, if you create an extra reference to an object, you
  12937. must INCREF it, if you throw away a reference to an object, you must
  12938. DECREF it.  Functions such as newstringobject, newsizedstringobject,
  12939. newintobject, etc. create a reference to an object.  If you want to
  12940. throw away the object thus created, you must use DECREF.
  12941.  
  12942. If you put an object into a tuple, list, or dictionary, the idea is
  12943. that you usually don't want to keep a reference of your own around, so
  12944. Python does not INCREF the elements.  It does DECREF the old value.
  12945. This means that if you put something into such an object using the
  12946. functions Python provides for this, you must INCREF the object if you
  12947. want to keep a separate reference to the object around.  Also, if you
  12948. replace an element, you should INCREF the old element first if you
  12949. want to keep it.  If you didn't INCREF it before you replaced it, you
  12950. are not allowed to look at it anymore, since it may have been freed.
  12951.  
  12952. Returning an object to Python (i.e., when your module function
  12953. returns) creates a reference to an object, but it does not change the
  12954. reference count.  When your module does not keep another reference to
  12955. the object, you should not INCREF or DECREF it.  When you do keep a
  12956. reference around, you should INCREF the object.  Also, when you return
  12957. a global object such as None, you should INCREF it.
  12958.  
  12959. If you want to return a tuple, you should consider using mkvalue.
  12960. Mkvalue creates a new tuple with a reference count of 1 which you can
  12961. return.  If any of the elements you put into the tuple are objects,
  12962. they are INCREFfed by mkvalue.  If you don't want to keep references
  12963. to those elements around, you should DECREF them after having called
  12964. mkvalue.
  12965.  
  12966. Usually you don't have to worry about arguments.  They are INCREFfed
  12967. before your function is called and DECREFfed after your function
  12968. returns.  When you keep a reference to an argument, you should INCREF
  12969. it and DECREF when you throw it away.  Also, when you return an
  12970. argument, you should INCREF it, because returning the argument creates
  12971. an extra reference to it.
  12972.  
  12973. If you use getargs() to parse the arguments, you can get a reference
  12974. to an object (by using "O" in the format string).  This object was not
  12975. INCREFfed, so you should not DECREF it.  If you want to keep the
  12976. object, you must INCREF it yourself.
  12977.  
  12978. If you create your own type of objects, you should use NEWOBJ to
  12979. create the object.  This sets the reference count to 1.  If you want
  12980. to throw away the object, you should use DECREF.  When the reference
  12981. count reaches 0, the dealloc function is called.  In it, you should
  12982. DECREF all object to which you keep references in your object, but you
  12983. should not use DECREF on your object.  You should use DEL instead.
  12984.  
  12985. Sjoerd Mullender
  12986. CWI, dept. CST, Kruislaan 413, 1098 SJ Amsterdam, Netherlands
  12987. email: Sjoerd.Mullender@cwi.nl        fax:   +31 20 592 4199
  12988. phone: +31 20 592 4127            telex: 12571 mactr nl
  12989. 
  12990. 
  12991. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  12992.     id AA09952 (5.65b/3.9/CWI-Amsterdam); Fri, 13 Aug 1993 17:51:06 +0200
  12993. From: Lance Ellinghouse <lance@markv.com>
  12994. X-Mailer: SCO System V Mail (version 3.2)
  12995. To: python-list@cwi.nl
  12996. Subject: updated nntpxmit.py file...
  12997. Date: Fri, 13 Aug 93 8:50:33 PDT
  12998. Message-Id:  <9308130850.aa26272@hermix.markv.com>
  12999.  
  13000. I have fixed a number of crashes and dumps that I was not
  13001. expecting in the nntpxmit.py file I posted a while ago..
  13002. It has been up and running for almost 2 weeks straight now!
  13003. (that's about 2 weeks more than the original nntpxmit!)
  13004.  
  13005. Lance Ellinghouse
  13006. lance@markv.com
  13007. =====
  13008. #! /usr/local/bin/python
  13009.  
  13010. # This file reads the batch files created by NNTP and 
  13011. # sends the messages to the remote site.
  13012.  
  13013. # The usage for this program is:  
  13014. #
  13015. # nntpxmit Batch_dir News_dir
  13016.  
  13017. import sys
  13018. import strop
  13019. import posix
  13020. import socket
  13021. from nntplib import NNTP, error_temp, error_reply, error_perm
  13022.  
  13023. False = 0
  13024. True  = 1
  13025.  
  13026. #####
  13027. # Global locations to use
  13028. #####
  13029. NewsSpoolDir = ''
  13030. NewsBatchDir = ''
  13031. if len(sys.argv) != 3:
  13032.     print 'Usage: ' + sys.argv[0] + ' NNTP_Batch_Dir NEWS_Directory'
  13033.     raise SystemExit
  13034. NewsSpoolDir = sys.argv[2] + '/'
  13035. NewsBatchDir = sys.argv[1] + '/'
  13036. NewsBatchHost= ''
  13037.  
  13038. #####
  13039. # Codes returned from NNTP Server
  13040. #####
  13041. OK_NOPOST    = 201
  13042. OK_CANPOST   = 200
  13043. OK_XFERD     = 235
  13044. CONT_XFER    = 335
  13045. ERR_GOTIT    = 435
  13046. ERR_XFERRJCT = 437
  13047. ERR_XFERFAIL = 436
  13048.  
  13049. #####
  13050. # Globals
  13051. #####
  13052. # Transfer Stats
  13053. Stats = {
  13054.     'offered':0,
  13055.     'accepted':0,
  13056.     'rejected':0,
  13057.     'failed':0
  13058.     }
  13059.     
  13060. Debug = False
  13061. Report_Stats = True
  13062. ReQueue_fails = True
  13063.  
  13064. Debug_Stream = None
  13065.  
  13066. Requeue_Article_lst = []
  13067.  
  13068. #####
  13069. # Support Functions
  13070. #####
  13071.  
  13072. def reset_stats():
  13073.         global Stats
  13074.         Stats['offered']  = 0
  13075.         Stats['accepted'] = 0
  13076.         Stats['rejected'] = 0
  13077.         Stats['failed']   = 0
  13078.         return None
  13079.  
  13080. def print_stats(host):
  13081.         global Stats
  13082.         print ''
  13083.         print 'Statistics for \'' + host + '\''
  13084.         print '='*30
  13085.         print 'Offered  : ' + `Stats['offered']`
  13086.         print 'Accepted : ' + `Stats['accepted']`
  13087.         print 'Rejected : ' + `Stats['rejected']`
  13088.         print 'Failed   : ' + `Stats['failed']`
  13089.         print ''
  13090.         return None
  13091.  
  13092. def write_requeue(file_name, lst):
  13093.     try:
  13094.         fp = open(NewsBatchDir + file_name,'a+')
  13095.     except IOError, msg:
  13096.         print 'write_requeue(' + NewsBatchDir + file_name + ') failed: ' + msg
  13097.         return None
  13098.     if len(lst) == 0:
  13099.         fp.close()
  13100.         return None
  13101.     for item in lst:
  13102.         try:
  13103.             fp.write(item[0] + ' ' + item[1] + '\n')
  13104.         except IOError, msg:
  13105.             print 'write_requeue(' + NewsBatchDir + file_name + ') failed: ' + msg
  13106.             return None
  13107.     return None
  13108.  
  13109. # This routine takes a file name and loads all the lines in the file
  13110. # into a list. This list contains 2 parts, ('filename','message id')
  13111. # This information is taked from a batch file
  13112. def load_batch(file_name):
  13113.     try:
  13114.         fp = open(file_name,'r')
  13115.     except:
  13116.         return None
  13117.     list = []
  13118.     list = fp.readlines()
  13119.     for ndx in range(len(list)):
  13120.         list_el = strop.strip(list[ndx])
  13121.         l = len(list_el)
  13122.         j = 0
  13123.         while j < l and list_el[j] != ' ':
  13124.             j = j + 1
  13125.         fn = list_el[0:j]
  13126.         msgid = list_el[j:]
  13127.         list[ndx] = (strop.strip(fn),strop.strip(msgid))
  13128.     try:
  13129.         t = posix.unlink(file_name)
  13130.     except:
  13131.         pass
  13132.     return list
  13133.  
  13134. # this will lock a directory
  13135. def lock_dir(dir_to_lock):
  13136.     t_dir = posix.getcwd()
  13137.     r = posix.chdir(dir_to_lock)
  13138.     try:
  13139.         r = open('.LCK'+`posix.getpid()`,'w')
  13140.     except:
  13141.         r = posix.chdir(t_dir)
  13142.         return False
  13143.     r.close()
  13144.     try:
  13145.         r = posix.link('.LCK'+`posix.getpid()`,'.LCKdir')
  13146.     except:
  13147.         r = posix.chdir(t_dir)
  13148.         return False
  13149.     r = posix.chdir(t_dir)
  13150.     return True
  13151.  
  13152. # This will unlock the directory
  13153. def unlock_dir(dir_to_unlock):
  13154.     t_dir = posix.getcwd()
  13155.     r = posix.chdir(dir_to_unlock)
  13156.     try:
  13157.         r = posix.unlink('.LCKdir')
  13158.         r = posix.unlink('.LCK'+`posix.getpid()`)
  13159.     except:
  13160.         return False
  13161.     r = posix.chdir(t_dir)
  13162.     return True
  13163.  
  13164. # This function returns 2 lists.. 
  13165. # 1: A list of all files in the directory that are NOT requeue files (! '~xxx')
  13166. # 2: A list of all files in the directory that are requeue files (~xxx)
  13167. # This function NEVER returns files that start as '.LCK' as these
  13168. # are lock files and Never need to be touched and it never returns
  13169. # files that start with '.' as these are hidden
  13170. def rtn_dirlist(dir_to_list):
  13171.     requeue_lst = []
  13172.     rtn_lst = []
  13173.     try:
  13174.         lst = posix.listdir(dir_to_list)
  13175.     except:
  13176.         return (None, None)
  13177.     for i in range(len(lst)):
  13178.         name = lst[i]
  13179.         if name[0] == '.':
  13180.             continue
  13181.         if name[0] == '~':
  13182.             r = requeue_lst.append(name)
  13183.             continue
  13184.         rtn_lst.append(name)
  13185.     return (rtn_lst, requeue_lst)
  13186.  
  13187. def process_file(f_name):
  13188.     global Requeue_Article_lst
  13189.     count = -1
  13190.     lst = load_batch(NewsBatchDir + f_name)
  13191.     if len(lst):
  13192.         reset_stats()
  13193.         try:
  13194.             if f_name[0] == '~':
  13195.                 host = f_name[1:]
  13196.             else:
  13197.                 host = f_name
  13198.             print 'Connecting to ' + host
  13199.             n = NNTP().init(host)
  13200.             print 'NNTP welcomes with \'' + n.getwelcome() + '\''
  13201.         except (EOFError,IOError,error_temp,error_perm,socket.error), msg:
  13202.             print 'NNTP connect failed: ' + `msg`
  13203.             for item in lst:
  13204.                 Requeue_Article_lst.append(item)
  13205.             return None
  13206.         for item in lst:
  13207.             count = count + 1
  13208.             try:
  13209.                 f = open(NewsSpoolDir + item[0],'r')
  13210.             except IOError, msg:
  13211.                 print 'opening of ' + NewsSpoolDir + item[0],
  13212.                 print ' failed: ' + `msg`
  13213.                 Stats['failed'] = Stats['failed'] + 1
  13214.                 continue
  13215.             try:
  13216.                 Stats['offered'] = Stats['offered'] + 1
  13217.                 rtn = n.ihave(item[1],f)
  13218.                 Stats['accepted'] = Stats['accepted'] + 1
  13219.             except error_temp,msg:
  13220.                 rtn_val = eval(msg[:3])
  13221.                 if rtn_val == ERR_XFERFAIL:
  13222.                     print 'Transfer failed: Requeuing ' + item[1]
  13223.                     Requeue_Article_lst.append(item)
  13224.                     Stats['failed'] = Stats['failed'] + 1
  13225.                 if rtn_val == ERR_GOTIT:
  13226.                     Stats['rejected'] = Stats['rejected'] + 1
  13227.             except EOFError, msg:
  13228.                 print 'Connection Closed!! requeueing items left'
  13229.                 print 'Returned: ' + `msg`
  13230.                 num_left = len(lst) - count
  13231.                 print 'Requeuing ' + `num_left` + ' items.'
  13232.                 for items in lst[count:]:
  13233.                     Requeue_Article_lst.append(items)
  13234.                 return None
  13235.     n.quit()
  13236.     print_stats(host)
  13237.     return None
  13238.  
  13239. # This is the main routine that runs everything
  13240. def main():
  13241.     global Stats
  13242.     global Requeue_Article_lst
  13243.     if not lock_dir(NewsBatchDir):
  13244.         print 'Could not lock \'' + NewsBatchDir + '\'.'
  13245.         print 'Try again later.'
  13246.         raise SystemExit
  13247.     do_list, redo_list = rtn_dirlist(NewsBatchDir)
  13248.     if redo_list != None and len(redo_list):
  13249.         for f_name in redo_list:
  13250.             process_file(f_name)
  13251.             if len(Requeue_Article_lst):
  13252.                 write_requeue(f_name,Requeue_Article_lst)
  13253.                 Requeue_Article_lst = []
  13254.     if do_list != None and len(do_list):
  13255.         for f_name in do_list:
  13256.             process_file(f_name)
  13257.             if len(Requeue_Article_lst):
  13258.                 write_requeue('~'+f_name,Requeue_Article_lst)
  13259.                 Requeue_Article_lst = []
  13260.     r = unlock_dir(NewsBatchDir)
  13261.     return None
  13262.  
  13263. main()
  13264.  
  13265. 
  13266. 
  13267. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  13268.     id AA06775 (5.65b/3.9/CWI-Amsterdam); Tue, 17 Aug 1993 05:00:58 +0200
  13269. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  13270.     id AA17740; Mon, 16 Aug 1993 22:59:41 -0400
  13271. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  13272.     id AA25341; Mon, 16 Aug 93 22:59:36 EDT
  13273. Received: by kaos.ksr.com (4.1/KSR-2.0)
  13274.     id AA26538; Mon, 16 Aug 93 22:59:33 EDT
  13275. Message-Id: <9308170259.AA26538@kaos.ksr.com>
  13276. To: python-list@cwi.nl
  13277. Subject: Date objects
  13278. Date: Mon, 16 Aug 93 22:59:32 -0400
  13279. From: Tim Peters <tim@ksr.com>
  13280.  
  13281. Attached is module Dates.py, which supplies a handy Date class that
  13282. supports date arithmetic (e.g., Dates.today() + 40*7 returns the date 40
  13283. weeks from now, Dates.Date(12,25,1993)-Dates.today() is the number of
  13284. days until Christmas, etc).  It uses features new in Python 0.9.9, so
  13285. you'll need to bring up the new release first; in return, I've extended
  13286. this to allow use of new 0.9.9 capabilites (e.g., Date objects can be
  13287. used as dictionary keys under 0.9.9).
  13288.  
  13289. I have 3 reasons for sending it out:
  13290.  
  13291. 1) I've found various versions of this to be useful, so maybe you will
  13292.    too.  Python's actual coercion rules aren't documented in full, so
  13293.    maybe studying this will save you some poke-and-hope time too.
  13294.  
  13295. 2) I'm wondering whether anyone sees a better way to worm around the
  13296.    coercion problems (date+date doesn't make sense, but date-date does
  13297.    and doesn't at all mean the same thing as date-int; etc).  The sole
  13298.    advantage of the strange method used here is that it works.
  13299.  
  13300. 3) I'm wondering whether other people have tried to implement new
  13301.    "numeric" types, and if so how that went for them.  I'm particularly
  13302.    curious as to whether you found that automatic coercion was more of a
  13303.    help or a stumbling block.  On the one hand, int+new_type has to go
  13304.    thru _some_ trickery else new_type.__add__ would get the arguments in
  13305.    the wrong order (as int*new_type already does ...); on the other,
  13306.    sometimes you really don't want to lose the info that the left (or
  13307.    right) argument was an int.
  13308.  
  13309.    That suggests:  (a) no automatic coercion; and (b), the __add__ etc
  13310.    methods would be better as two methods, say __addl__ and __addr__,
  13311.    that distinguished between new-type-was-on-the-left and new-type-
  13312.    was-on-the-right.
  13313.  
  13314.    It also suggests that maybe date arithmetic is an abuse of the
  13315.    intended uses <grin>.
  13316.  
  13317. curiously y'rs  - tim
  13318.  
  13319. Tim Peters   tim@ksr.com
  13320. not speaking for Kendall Square Research Corp
  13321.  
  13322.  
  13323. # Class Date supplies date objects that support date arithmetic.
  13324. #
  13325. # Date(month,day,year) returns a Date object.  An instance prints as,
  13326. # e.g., 'Mon 16 Aug 1993'.
  13327. #
  13328. # Addition, subtraction, comparison operators, min, max, and sorting
  13329. # all work as expected for date objects:  int+date or date+int returns
  13330. # the date `int' days from `date'; date+date raises an exception;
  13331. # date-int returns the date `int' days before `date'; date2-date1 returns
  13332. # an integer, the number of days from date1 to date2; int-date raises an
  13333. # exception; date1 < date2 is true iff date1 occurs before date2 (&
  13334. # similarly for other comparisons); min(date1,date2) is the earlier of
  13335. # the two dates and max(date1,date2) the later; and date objects can be
  13336. # used as dictionary keys.
  13337. #
  13338. # Date objects support one visible method, date.weekday().  This returns
  13339. # the day of the week the date falls on, as a string.
  13340. #
  13341. # Date objects also have 4 (conceptually) read-only data attributes:
  13342. #   .month  in 1..12
  13343. #   .day    in 1..31
  13344. #   .year   int or long int
  13345. #   .ord    the ordinal of the date relative to an arbitrary staring point
  13346. #
  13347. # The Dates module also supplies function today(), which returns the
  13348. # current date as a date object.
  13349. #
  13350. # Those entranced by calendar trivia will be disappointed, as no attempt
  13351. # has been made to accommodate the Julian (etc) system.  On the other
  13352. # hand, at least this package knows that 2000 is a leap year but 2100
  13353. # isn't, and works fine for years with a hundred decimal digits <wink>.
  13354.  
  13355. _MONTH_NAMES = [ 'January', 'February', 'March', 'April', 'May',
  13356.          'June', 'July', 'August', 'September', 'October',
  13357.          'November', 'December' ]
  13358.  
  13359. _DAY_NAMES = [ 'Friday', 'Saturday', 'Sunday', 'Monday',
  13360.            'Tuesday', 'Wednesday', 'Thursday' ]
  13361.  
  13362. _DAYS_IN_MONTH = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
  13363.  
  13364. _DAYS_BEFORE_MONTH = []
  13365. dbm = 0
  13366. for dim in _DAYS_IN_MONTH:
  13367.     _DAYS_BEFORE_MONTH.append(dbm)
  13368.     dbm = dbm + dim
  13369. del dbm, dim
  13370.  
  13371. _INT_TYPES = type(1), type(1L)
  13372.  
  13373. def _is_leap( year ):        # 1 if leap year, else 0
  13374.     if year % 4 != 0: return 0
  13375.     if year % 400 == 0: return 1
  13376.     return year % 100 != 0
  13377.  
  13378. def _days_in_year( year ):    # number of days in year
  13379.     return 365 + _is_leap(year)
  13380.  
  13381. def _days_before_year( year ):    # number of days before year
  13382.     return year*365L + (year+3)/4 - (year+99)/100 + (year+399)/400
  13383.  
  13384. def _days_in_month( month, year ):    # number of days in month of year
  13385.     if month == 2 and _is_leap(year): return 29
  13386.     return _DAYS_IN_MONTH[month-1]
  13387.  
  13388. def _days_before_month( month, year ):    # number of days in year before month
  13389.     return _DAYS_BEFORE_MONTH[month-1] + (month > 2 and _is_leap(year))
  13390.  
  13391. def _date2num( date ):        # compute ordinal of date.month,day,year
  13392.     return _days_before_year( date.year ) + \
  13393.        _days_before_month( date.month, date.year ) + \
  13394.        date.day
  13395.  
  13396. _DI400Y = _days_before_year( 400 )    # number of days in 400 years
  13397.  
  13398. def _num2date( n ):        # return date with ordinal n
  13399.     if type(n) not in _INT_TYPES:
  13400.     raise TypeError, 'argument must be integer: ' + `type(n)`
  13401.  
  13402.     ans = Date(1,1,1)    # arguments irrelevant; just getting a Date obj
  13403.     ans.ord = n
  13404.  
  13405.     n400 = (n-1)/_DI400Y        # # of 400-year blocks preceding
  13406.     year, n = 400 * n400, n - _DI400Y * n400
  13407.     more = n / 365
  13408.     dby = _days_before_year( more )
  13409.     if dby >= n:
  13410.     more = more - 1
  13411.     dby = dby - _days_in_year( more )
  13412.     year, n = year + more, int(n - dby)
  13413.  
  13414.     try: year = int(year)        # chop to int, if it fits
  13415.     except ValueError: pass
  13416.  
  13417.     month = min( n/29 + 1, 12 )
  13418.     dbm = _days_before_month( month, year )
  13419.     if dbm >= n:
  13420.     month = month - 1
  13421.     dbm = dbm - _days_in_month( month, year )
  13422.  
  13423.     ans.month, ans.day, ans.year = month, n-dbm, year
  13424.     return ans
  13425.  
  13426. def _num2day( n ):    # return weekday name of day with ordinal n
  13427.     return _DAY_NAMES[ int(n % 7) ]
  13428.  
  13429.  
  13430. class Date:
  13431.     def __init__( self, month, day, year ):
  13432.     if not 1 <= month <= 12:
  13433.         raise ValueError, 'month must be in 1..12: ' + `month`
  13434.     dim = _days_in_month( month, year )
  13435.     if not 1 <= day <= dim:
  13436.         raise ValueError, 'day must be in 1..' + `dim` + ': ' + `day`
  13437.     self.month, self.day, self.year = month, day, year
  13438.     self.ord = _date2num( self )
  13439.  
  13440.     def __cmp__( self, other ):
  13441.     return cmp( self.ord, other.ord )
  13442.  
  13443.     # define a hash function so dates can be used as dictionary keys
  13444.     def __hash__( self ):
  13445.     return hash( self.ord )
  13446.  
  13447.     # print as, e.g., Mon 16 Aug 1993
  13448.     def __repr__( self ):
  13449.     return '%.3s %2d %.3s ' % (
  13450.           self.weekday(),
  13451.           self.day,
  13452.           _MONTH_NAMES[self.month-1] ) + `self.year`
  13453.  
  13454.     # automatic coercion is a pain for date arithmetic, since e.g.
  13455.     # date-date and date-int mean different things.  So, in order to
  13456.     # sneak integers past Python's coercion rules without losing the info
  13457.     # that they're really integers (& not dates!), integers are disguised
  13458.     # as instances of the derived class _DisguisedInt.  That this works
  13459.     # relies on undocumented behavior of Python's coercion rules.
  13460.     def __coerce__( self, other ):
  13461.     if type(other) in _INT_TYPES:
  13462.         return self, _DisguisedInt(other)
  13463.     # if another Date, fine
  13464.     if type(other) is type(self) and other.__class__ is Date:
  13465.         return self, other
  13466.  
  13467.     # Python coerces int+date, but not date+int; in the former case,
  13468.     # _DisguisedInt.__add__ handles it, so we only need to do
  13469.     # date+int here
  13470.     def __add__( self, n ):
  13471.     if type(n) not in _INT_TYPES:
  13472.         raise TypeError, 'can\'t add ' + `type(n)` + ' to date'
  13473.     return _num2date( self.ord + n )
  13474.  
  13475.     # Python coerces all of int-date, date-int and date-date; the first
  13476.     # case winds up in _DisguisedInt.__sub__, leaving the latter two
  13477.     # for us
  13478.     def __sub__( self, other ):
  13479.     if other.__class__ is _DisguisedInt:    # date-int
  13480.         return _num2date( self.ord - other.ord )
  13481.     else:
  13482.         return self.ord - other.ord        # date-date
  13483.  
  13484.     def weekday( self ):
  13485.     return _num2day( self.ord )
  13486.  
  13487. # see comments before Date.__add__
  13488. class _DisguisedInt( Date ):
  13489.     def __init__( self, n ):
  13490.     self.ord = n
  13491.  
  13492.     # handle int+date
  13493.     def __add__( self, other ):
  13494.     return other.__add__( self.ord )
  13495.  
  13496.     # complain about int-date
  13497.     def __sub__( self, other ):
  13498.     raise TypeError, 'Can\'t subtract date from integer'
  13499.  
  13500. def today():
  13501.     import time
  13502.     local = time.localtime(time.time())
  13503.     return Date( local[1], local[2], local[0] )
  13504.  
  13505. DateTestError = 'DateTestError'
  13506. def test( firstyear, lastyear ):
  13507.     a = Date(9,30,1913)
  13508.     b = Date(9,30,1914)
  13509.     if `a` != 'Tue 30 Sep 1913':
  13510.     raise DateTestError, '__repr__ failure'
  13511.     if (not a < b) or a == b or a > b or b != b or \
  13512.       a != 698982 or 698982 != a or \
  13513.       (not a > 5) or (not 5 < a):
  13514.     raise DateTestError, '__cmp__ failure'
  13515.     if a+365 != b or 365+a != b:
  13516.     raise DateTestError, '__add__ failure'
  13517.     if b-a != 365 or b-365 != a:
  13518.     raise DateTestError, '__sub__ failure'
  13519.     try:
  13520.     x = 1 - a
  13521.     raise DateTestError, 'int-date should have failed'
  13522.     except TypeError:
  13523.     pass
  13524.     try:
  13525.     x = a + b
  13526.     raise DateTestError, 'date+date should have failed'
  13527.     except TypeError:
  13528.     pass
  13529.     if a.weekday() != 'Tuesday':
  13530.     raise DateTestError, 'weekday() failure'
  13531.     if max(a,b) is not b or min(a,b) is not a:
  13532.     raise DateTestError, 'min/max failure'
  13533.     d = {a-1:b, b:a+1}
  13534.     if d[b-366] != b or d[a+(b-a)] != Date(10,1,1913):
  13535.     raise DateTestError, 'dictionary failure'
  13536.  
  13537.     # verify date<->number conversions for first and last days for
  13538.     # all years in firstyear .. lastyear
  13539.  
  13540.     lord = _days_before_year( firstyear )
  13541.     y = firstyear
  13542.     while y <= lastyear:
  13543.     ford = lord + 1
  13544.     lord = ford + _days_in_year(y) - 1
  13545.     fd, ld = Date(1,1,y), Date(12,31,y)
  13546.     if (fd.ord,ld.ord) != (ford,lord):
  13547.         raise DateTestError, ('date->num failed', y)
  13548.     fd, ld = _num2date(ford), _num2date(lord)
  13549.     if (1,1,y,12,31,y) != \
  13550.        (fd.month,fd.day,fd.year,ld.month,ld.day,ld.year):
  13551.         raise DateTestError, ('num->date failed', y)
  13552.     y = y + 1
  13553.  
  13554.  
  13555. >>> END OF MSG
  13556. 
  13557. 
  13558. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  13559.     id AA22278 (5.65b/3.9/CWI-Amsterdam); Tue, 17 Aug 1993 11:33:43 +0200
  13560. Received: by schelvis.cwi.nl with SMTP
  13561.     id AA02991 (5.65b/3.8/CWI-Amsterdam); Tue, 17 Aug 1993 11:33:41 +0200
  13562. Message-Id: <9308170933.AA02991=jack@schelvis.cwi.nl>
  13563. To: Tim Peters <tim@ksr.com>
  13564. Cc: python-list@cwi.nl
  13565. Subject: Re: Date objects 
  13566. In-Reply-To: Message by Tim Peters <tim@ksr.com> ,
  13567.          Mon, 16 Aug 93 22:59:32 -0400 , <9308170259.AA26538@kaos.ksr.com> 
  13568. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  13569. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  13570. X-Last-Band-Seen: Manic Street Preachers (Melkweg, 15-8), Windmills (Kroeg)
  13571. X-Mini-Review: MSP: uneventful. Windmills: Great!
  13572. Date: Tue, 17 Aug 1993 11:33:40 +0200
  13573. From: Jack Jansen <Jack.Jansen@cwi.nl>
  13574.  
  13575. Wonderful! This means that an unbirthday program in python is now only
  13576. a couple of lines:
  13577.  
  13578. import Date
  13579. import sys
  13580.  
  13581. print 'Enter your day of birth as (day, month, year) - '
  13582. d, m, y = eval(sys.stdin.readline())
  13583. birth = Date.Date(m, d, y)
  13584. today = Date.today()
  13585. this_years_birthday = Date.Date(m, d, today.year)
  13586. if this_years_birthday == today:
  13587.     print 'It is your', `today.year-y`+'th birthday today! Congratulations!'
  13588. else:
  13589.     unbirthday = (today-birth)-(today.year-y)
  13590.     if this_years_birthday > today:
  13591.         unbirthday = unbirthday + 1
  13592.     print 'Today is your', `int(unbirthday)`+'th unbirthday today! Congratulations!'
  13593.  
  13594. --
  13595. Jack Jansen        | If I can't dance I don't want to be part of
  13596. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  13597. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  13598. 
  13599. 
  13600. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  13601.     id AA21447 (5.65b/3.9/CWI-Amsterdam); Sat, 21 Aug 1993 01:54:38 +0200
  13602. From: Lance Ellinghouse <lance@markv.com>
  13603. X-Mailer: SCO System V Mail (version 3.2)
  13604. To: python-list@cwi.nl
  13605. Subject: PYTHON FTP sites...
  13606. Date: Fri, 20 Aug 93 16:53:59 PDT
  13607. Message-Id:  <9308201654.aa25072@hermix.markv.com>
  13608.  
  13609. Are there any FTP sites for PYTHON code besides ftp.cwi.nl???
  13610.  
  13611. Lance Ellinghouse
  13612. lance@markv.com
  13613. 
  13614. 
  13615. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  13616.     id AA00792 (5.65b/3.10/CWI-Amsterdam); Wed, 25 Aug 1993 20:33:12 +0200
  13617. From: Lance Ellinghouse <lance@markv.com>
  13618. X-Mailer: SCO System V Mail (version 3.2)
  13619. To: python-list@cwi.nl
  13620. Subject: rpc.py
  13621. Date: Wed, 25 Aug 93 11:32:00 PDT
  13622. Message-Id:  <9308251132.aa15655@hermix.markv.com>
  13623.  
  13624. I am working with the rpc.py module to create a set of server/client
  13625. processes.. The problem I am having is that I wish to define a
  13626. class that uses the Server and Client classes as:
  13627.  
  13628. class MyServer(TCPServer, TCPClient):
  13629. ......
  13630.  
  13631. I can use any method in TCPServer, but I cannot use any methods in
  13632. TCPClient. It does not seem to see the TCPClient at all..
  13633. I DO NOT call the TCPClient.init() routine since I already call
  13634. the TCPServer.init() call... Does this have something to do with it?
  13635.  
  13636. Thank you!
  13637. Lance Ellinghouse
  13638. lance@markv.com
  13639. 
  13640. 
  13641. Received: from ansjovis.cwi.nl by charon.cwi.nl with SMTP
  13642.     id AA06232 (5.65b/3.10/CWI-Amsterdam); Wed, 25 Aug 1993 23:53:32 +0200
  13643. Received: by ansjovis.cwi.nl with SMTP
  13644.     id AA15498 (5.65b/3.8/CWI-Amsterdam); Wed, 25 Aug 1993 23:53:31 +0200
  13645. Message-Id: <9308252153.AA15498=sjoerd@ansjovis.cwi.nl>
  13646. To: Lance Ellinghouse <lance@markv.com>
  13647. Cc: python-list@cwi.nl
  13648. Subject: Re: rpc.py 
  13649. In-Reply-To: Your message of Wed, 25 Aug 1993 11:32:00 -0700.
  13650.              <9308251132.aa15655@hermix.markv.com> 
  13651. Date: Wed, 25 Aug 1993 23:53:30 +0200
  13652. From: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
  13653.  
  13654. On Wed, Aug 25 1993 Lance Ellinghouse wrote:
  13655.  
  13656. > I am working with the rpc.py module to create a set of server/client
  13657. > processes.. The problem I am having is that I wish to define a
  13658. > class that uses the Server and Client classes as:
  13659. > class MyServer(TCPServer, TCPClient):
  13660. > ......
  13661. > I can use any method in TCPServer, but I cannot use any methods in
  13662. > TCPClient. It does not seem to see the TCPClient at all..
  13663. > I DO NOT call the TCPClient.init() routine since I already call
  13664. > the TCPServer.init() call... Does this have something to do with it?
  13665.  
  13666. It seems to me that you are trying to live dangerously.  I don't know
  13667. the rpc module, but I had a quick look, and it seems that both classes
  13668. use the same names for instance variables.  This means that you really
  13669. have only one set of instance variables instead of one for both the
  13670. server and the client.
  13671.  
  13672. An alternative would be to not inherit from the two classes but to
  13673. create instance variables in your class that are instances of the two
  13674. classes you mention:
  13675.  
  13676. class MyServer:
  13677.     def init(self,...):
  13678.         self.server = TCPServer().init(...)
  13679.         self.client = TCPClient().init(...)
  13680.  
  13681. Ordinarily, if you inherit from two super classes, you should call the
  13682. init() methods of both super classes.
  13683.  
  13684. Sjoerd Mullender
  13685. CWI, dept. CST, Kruislaan 413, 1098 SJ Amsterdam, Netherlands
  13686. email: Sjoerd.Mullender@cwi.nl        fax:   +31 20 592 4199
  13687. phone: +31 20 592 4127            telex: 12571 mactr nl
  13688. 
  13689. 
  13690. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  13691.     id AA07704 (5.65b/3.10/CWI-Amsterdam); Thu, 26 Aug 1993 11:16:27 +0200
  13692. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  13693.     id AA07627; Thu, 26 Aug 1993 05:15:29 -0400
  13694. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  13695.     id AA27612; Thu, 26 Aug 93 05:15:14 EDT
  13696. Received: by kaos.ksr.com (4.1/KSR-2.0)
  13697.     id AA03341; Thu, 26 Aug 93 05:14:42 EDT
  13698. Message-Id: <9308260914.AA03341@kaos.ksr.com>
  13699. To: python-list@cwi.nl, allen@ksr.com
  13700. Subject: Rats
  13701. Date: Thu, 26 Aug 93 05:14:42 -0400
  13702. From: Tim Peters <tim@ksr.com>
  13703.  
  13704. Attached is a drop-in replacement for the rational-arithmetic class
  13705. distributed as python/demo/classes/Rat.py.  In comparison to that, this
  13706. version:
  13707.  
  13708.  - plugs some holes
  13709.  
  13710.  - adds support for 0.9.9 features (e.g., a rat can be used as a
  13711.    dictionary key)
  13712.  
  13713.  - suffers spurious overflow less often for short-rat operations (and
  13714.    never for * and / and comparisons)
  13715.  
  13716.  - runs much faster for long-rat operations
  13717.  
  13718.  - provides an exact way to convert floats to rationals
  13719.  
  13720.  - is (or is intended to be <wink>) upward-compatible
  13721.  
  13722.  - supports the same (but extended) interface (through function Rats.rat)
  13723.  
  13724. Irony:  When I posted a Dates module, I moaned that automatic coercion
  13725. got in the way.  While beefing up the Rat module, automatic coercion was
  13726. to the contrary a wonderful thing to have, and indeed its lack for + and
  13727. * was painful to worm around.
  13728.  
  13729. I believe the method for worming around that used below is about as clean
  13730. & general an approach as can be crafted in Python today (if you don't see
  13731. the problem this is trying to solve, figure out why, e.g., "rat(2,3) -
  13732. 3.0" and "3.0 - rat(2,3)" both invoke Rat.__coerce__ but do not invoke
  13733. Rat.__sub__; then consider that "rat(2,3) + 3.0" will invoke Rat.__add__
  13734. (with 3.0 as the second argument) but not Rat.__coerce__, while "3.0 +
  13735. rat(2,3)" will invoke Rat.__coerce__ but not Rat.__add__; on the other
  13736. hand, 3.0*rat(2,3) and rat(2,3)*3.0 both invoke Rat.__mul__ without going
  13737. through Rat.__coerce__ first ... __add__ and __mul__ are different from
  13738. all the others, and from each other).
  13739.  
  13740. Nevertheless, in both the Dates modules & this one, all the problems
  13741. could be worked around, so it's hard to whine too much ...
  13742.  
  13743. just-practicing<grin>-ly y'rs  - tim
  13744.  
  13745.  
  13746. # Rational Numbers
  13747. #
  13748. # Supplies function `rat' for creating rational-number objects (RNO).
  13749. # RNOs support mixed-mode arithmetic (+-*/, pow, unary -), comparisons
  13750. # (==, <=, etc), coercion (to float, int, long), and hashing (so an RNO
  13751. # can be used as a dictionary key).  In Boolean contexts, an RNO is true
  13752. # if & only if it's non-zero.
  13753. #
  13754. # In mixed-mode arithmetic, ints and longs are converted to rationals,
  13755. # while rationals are converted to floats.  Function `rat' can be used
  13756. # explicitly to convert a float to an exact rational equivalent.
  13757. #
  13758. # Given an RNO r, r is the rational number r.num/r.den.  r.den > 0
  13759. # always, and r.num and r.den have no non-unit common factor.  Along with
  13760. # the convention that 0 is represented as 0/1, this implies each
  13761. # mathematical rational has a unique representation as an RNO. .num and
  13762. # .den are intended to be read-only attributes, so that the module can
  13763. # maintain these properties.
  13764. #
  13765. # RNOs come in two flavors:  short rats and long rats.  The difference is
  13766. # solely whether .num and .den are Python integers or long integers.
  13767. # Short rats will in general run substantially faster, but this is of
  13768. # limited utility since the size of numerators & denominators tends to
  13769. # blow up quickly during a chain of rational operations.  In addition,
  13770. # except for comparisons, an operation on short rats may raise an
  13771. # overflow exception during an intermediate calculation, even if the
  13772. # final result would be representable as a short rat.  The author
  13773. # recommends not using short rats at all unless you know exactly what
  13774. # you're doing.
  13775. #
  13776. # Function rat accepts these arguments:
  13777. #   rat(long a)  returns long rat equal to a
  13778. #   rat(int  a)  returns short rat equal to a
  13779. #
  13780. #   rat(long a,long b)  returns long rat equal to a/b
  13781. #   rat(long a, int b)  returns long rat equal to a/b
  13782. #   rat( int a,long b)    returns long rat equal to a/b
  13783. #   rat( int a, int b)  returns short rat equal to a/b
  13784. #
  13785. #   rat(float x)  returns long rat a/b exactly equal to x;
  13786. #          if x is bizarre (e.g., NaN or infinity on an IEEE
  13787. #          machine), the result is undefined
  13788. #
  13789. #
  13790. # SOME INTERNAL DETAILS
  13791. #
  13792. # The algorithms are obvious, or adapted from Knuth Volume 2.  The
  13793. # slowest part of a rational implementation is gcd calculations, so the
  13794. # operations are coded "cleverly" to avoid gcd whenever possible, and--
  13795. # when gcd can't be avoided --to minimize the size of the operands passed
  13796. # to gcd.
  13797. #
  13798. # Speeding gcd itself is difficult.  The speed of gcd depends mostly on
  13799. # the speed of division.  5 gcd functions are defined here, gcd1 through
  13800. # gcd5, that vary in their zeal to avoid divisions.  No single function
  13801. # is fastest; instead their speed depends on the size of the operands.
  13802. # From fastest to slowest, they are:
  13803. #
  13804. # for short arguments   for larger arguments (up      for huge arguments
  13805. # (Python int)          to several thousand bits)     (many thousand bits)
  13806. # -------------------   ---------------------------   --------------------
  13807. # gcd1                  gcd5                          gcd4
  13808. # gcd2                  gcd2                          gcd3
  13809. # gcd5                  gcd1                          gcd5
  13810. # gcd3                  gcd3                          gcd2
  13811. # gcd4                  gcd4                          gcd1
  13812. #
  13813. # There is some sense to this <wink>:  gcd1 does the most divisions,
  13814. # but it's also the simplest code.  For short arguments, saving the
  13815. # cost of a short division is overwhelmed by the overhead of executing
  13816. # more interpreted statements.  Contrarily, gcd4 does the fewest
  13817. # divisions but is the most complex code.  Pure binary methods aren't
  13818. # included here because they were never faster than the division
  13819. # methods (& I expect this is an artifact of using an interpreter;
  13820. # also that there's no really efficient way to test the last bit of
  13821. # a Python long ("x & 1" appears to create a long of x's length, then
  13822. # cut it back, making a conceptual O(1) operation an O(log x) operation;
  13823. # maybe "odd(x)" could be a builtin?)).
  13824. #
  13825. # gcd is set to gcd2 below, because that's the best compromise for
  13826. # the size of rationals the author usually works with (usually a few
  13827. # hundred to a couple thousand bits).  Bind gcd to one of the other
  13828. # routines if your usage is different.
  13829.  
  13830. import math
  13831.  
  13832. def rat(*args):
  13833.     if len(args) == 2:
  13834.     return Rat().init( args[0], args[1] )
  13835.  
  13836.     elif len(args) == 1:
  13837.     arg = args[0]
  13838.     t = type(arg)
  13839.     if t in (type(1), type(1L)):
  13840.         return apply( _rat, coerce(arg,1) )
  13841.  
  13842.     elif t is not type(1.0):
  13843.         raise TypeError, 'need integer or float argument'
  13844.  
  13845.     # convert float to rational; the method here is exact provided
  13846.     # that math.frexp and math.ldexp are exact (which they should be,
  13847.     # on binary machines)
  13848.  
  13849.     # take care of negative and 0
  13850.     if arg == 0.0:
  13851.         return _rat(0L,1L)
  13852.     top = bot = 1L
  13853.     if arg < 0.0: top, arg = -top, -arg
  13854.  
  13855.     # now arg > 0, and  arg * top / bot == original arg;
  13856.     # maintain that equality as an invariant while scaling
  13857.     # so that 0.5 <= arg < 1
  13858.     arg, shift = math.frexp( arg )
  13859.     if shift < 0:
  13860.         bot = bot << (-shift)
  13861.     elif shift > 0:
  13862.         top = top << shift
  13863.     answer = _rat( top, bot )
  13864.  
  13865.     # now arg in [0.5,1.0), and arg*answer == original arg;
  13866.     # remains to convert arg and multiply by answer;
  13867.     # suck up 28 bits at a time:  small enough to fit in an int,
  13868.     # and big enough so that any IEEE double will be done in no
  13869.     # more than 2 iterations
  13870.     top, bot = 0L, 1L
  13871.     while arg:
  13872.         arg28 = math.ldexp(arg, 28)    # arg * 2^28
  13873.         ip      = math.floor(arg28)    # next 28 bits
  13874.         top, bot = top << 28, bot << 28
  13875.         top, arg = top + int(ip), arg28 - ip
  13876.     return rat(top,bot) * answer
  13877.  
  13878.     else:
  13879.     raise TypeError, 'need 1 or 2 arguments'
  13880.  
  13881. # _rat packs top/bot into a rational; it trusts they have no common
  13882. # factor, that 0 is passed as (0,1), that bot != 0, and that they're both
  13883. # ints or long ints; this avoids the expensive gcd in Rat.init
  13884. def _rat( top, bot ):
  13885.     if bot < 0: top, bot = -top, -bot
  13886.     answer = Rat()
  13887.     answer.num, answer.den = top, bot
  13888.     return answer
  13889.  
  13890. # -------------------- GCD routines --------------------
  13891. # as simple as they get
  13892. def gcd1(a, b):
  13893.     while b:
  13894.     a, b = b, a % b
  13895.     return abs(a)
  13896.  
  13897. # since the quotient is 1 some 41% of the time, this one tries
  13898. # to save the division in that common case; gcd5 carries the
  13899. # idea one more step
  13900. def gcd2(a, b):
  13901.     a, b = abs(a), abs(b)
  13902.     if a < b: a, b = b, a
  13903.     while b:
  13904.     rem = a - b
  13905.     if rem < b:
  13906.         a, b = b, rem
  13907.     else:
  13908.         a, b = b, rem % b
  13909.     return a
  13910.  
  13911. # a mix of division & binary methods.  a & b are forced odd.  Then
  13912. # if r = a % b is odd, b-r is even.  So one of {r,b-r} is even.
  13913. # Factors of 2 are shifted out of that until it's odd again, and
  13914. # we do it again with the new odd pair.  gcd4 is an extension of
  13915. # this idea.
  13916. def gcd3(a, b):
  13917.     a, b, ashift, bshift = abs(a), abs(b), 0, 0
  13918.     if b == 0: return a
  13919.     if a == 0: return b
  13920.     while a & 1 == 0: a, ashift = a>>1, ashift+1
  13921.     while b & 1 == 0: b, bshift = b>>1, bshift+1
  13922.     r = a % b
  13923.     if r & 1: r = b - r
  13924.     a, b = b, r
  13925.     while b:
  13926.     b = b >> 1
  13927.     while b & 1 == 0: b = b >> 1
  13928.     r = a % b
  13929.     if r & 1: r = b - r
  13930.     a, b = b, r
  13931.     return a << min( ashift, bshift )
  13932.  
  13933. # like gcd3, but takes min(r,b-r) after removing factors of 2.  This
  13934. # guarantees that, after the first iteration, a/b >= 3, so we get
  13935. # some real benefit out of the division.  Alas, the interpreter
  13936. # overhead is high enough that it doesn't actually pay off until the
  13937. # arguments are over (about, on one particular machine) 10,000 bits long.
  13938. def gcd4(a, b):
  13939.     a, b = abs(a), abs(b)
  13940.     if a == 0 or b == 0: return max(a,b)
  13941.     ash = bsh = 0
  13942.     mask = 1L
  13943.     while (a & mask) == 0: mask, ash = mask<<1, ash+1
  13944.     mask = 1L
  13945.     while (b & mask) == 0: mask, bsh = mask<<1, bsh+1
  13946.     a, b = a>>ash, b>>bsh
  13947.     if a < b: a, b = b, a
  13948.     r = a % b
  13949.     while r:
  13950.     r2 = b - r
  13951.     mask, rsh = 2L, 1
  13952.     if r & 1:
  13953.         while (r2 & mask) == 0: mask, rsh = mask<<1, rsh+1
  13954.         r2 = r2 >> rsh
  13955.     else:
  13956.         while (r & mask) == 0: mask, rsh = mask<<1, rsh+1
  13957.         r = r >> rsh
  13958.     a, b = b, min(r,r2)
  13959.     r = a % b
  13960.     return b << min(ash,bsh)
  13961.  
  13962. # carrying gcd2 one more step, to avoid division when the quotient is
  13963. # 1 (about 41% of the time) or 2 (about 17% of the time)
  13964. def gcd5(a, b):
  13965.     a, b = abs(a), abs(b)
  13966.     if a < b: a, b = b, a
  13967.     while b:
  13968.     rem = a - b
  13969.     if rem < b:
  13970.         a, b = b, rem
  13971.     else:
  13972.         rem = rem - b
  13973.         if rem < b:
  13974.         a, b = b, rem
  13975.         else:
  13976.         a, b = b, rem % b
  13977.     return a
  13978.  
  13979. gcd = gcd2                # see comments at the start
  13980.  
  13981. # return (l, ma, mb) where
  13982. #   l is the least common multiple of a and b
  13983. #   ma * a = l
  13984. #   mb * b = l
  13985. def lcm(a, b):
  13986.     g = gcd( a, b )
  13987.     ma, mb = b/g, a/g
  13988.     return ma * a, ma, mb
  13989.  
  13990. # -------------------- class Rat --------------------
  13991. class Rat:
  13992.  
  13993.     def init(self, num, den):
  13994.     num, den = coerce( num, den )
  13995.     if type(num) not in (type(0), type(0L)):
  13996.         raise TypeError, 'rational must have integer components'
  13997.     if den < 0:
  13998.         num, den = -num, -den
  13999.     elif den == 0:
  14000.         raise ZeroDivisionError, 'rat(x, 0)'
  14001.     g = gcd(num, den)
  14002.     self.num = num/g
  14003.     self.den = den/g
  14004.     return self
  14005.  
  14006.     def __repr__(self):
  14007.     if self.den != 1:
  14008.         return 'rat' + `self.num, self.den`
  14009.     return 'rat(' + `self.num` + ')'
  14010.  
  14011.     def __cmp__(a, b):
  14012.     # relies on denominators being non-negative
  14013.     try:
  14014.         return cmp( a.num*b.den, a.den*b.num )
  14015.     except OverflowError:
  14016.         return cmp( long(a.num)*b.den, long(a.den)*b.num )
  14017.  
  14018.     def __hash__(self):
  14019.     return hash(self.num) ^ hash(self.den)
  14020.  
  14021.     def __float__(self):
  14022.     return float(self.num) / float(self.den)
  14023.  
  14024.     def __long__(self):
  14025.     return long(self.num) / long(self.den)
  14026.  
  14027.     def __int__(self):
  14028.     return int(self.num / self.den)
  14029.  
  14030.     def __coerce__(a, b):
  14031.     t = type(b)
  14032.     if t is type(a) and b.__class__ is Rat:
  14033.         return a, b
  14034.     if t is type(0):
  14035.         return a, rat(b, 1)
  14036.     if t is type(0L):
  14037.         return a, rat(b, 1L)
  14038.     if t is type(0.0):
  14039.         return a.__float__(), b
  14040.     return None
  14041.  
  14042.     def __nonzero__(self):
  14043.     return self.num != 0
  14044.  
  14045.     # Automatic coercion may not take place for + and *, so we check the
  14046.     # type of b and force coercion if it's not Rat.  Note that after
  14047.     # coercion, there's still no guarantee that the type of b is Rat (or
  14048.     # the type of a!), since type(coerce(Rat,float)) is float.  We worm
  14049.     # around that by reissuing the operation, letting Python figure out
  14050.     # how to do it.
  14051.     def __add__(a, b):
  14052.     if type(b) is type(a) and b.__class__ is Rat:
  14053.         g = gcd( a.den, b.den )
  14054.         if g == 1:
  14055.         return _rat( a.num*b.den + b.num*a.den, a.den*b.den )
  14056.         adenoverg = a.den/g
  14057.         top = a.num*(b.den/g) + b.num*adenoverg
  14058.         g2 = gcd( top, g )
  14059.         return _rat( top/g2, adenoverg * (b.den/g2) )
  14060.     a, b = coerce( a, b )
  14061.     return a + b
  14062.  
  14063.     def __mul__(a, b):
  14064.     if type(b) is type(a) and b.__class__ is Rat:
  14065.         g1, g2 = gcd(a.num,b.den), gcd(a.den,b.num)
  14066.         return _rat( (a.num/g1)*(b.num/g2),
  14067.              (a.den/g2)*(b.den/g1) )
  14068.     a, b = coerce( a, b )
  14069.     return a * b
  14070.  
  14071.     def __sub__(a, b):
  14072.     return a.__add__( -b )
  14073.  
  14074.     def __div__(a, b):
  14075.     if b.num:
  14076.         return a.__mul__( _rat( b.den, b.num ) )
  14077.     raise ZeroDivisionError, 'rational division by 0'
  14078.  
  14079.     def __neg__(self):
  14080.     a = Rat()
  14081.     a.num, a.den = -self.num, self.den
  14082.     return a
  14083.  
  14084.     def __pow__(a, n):
  14085.     if n.den == 1:
  14086.         n = n.num
  14087.         if n < 0: a, n = 1/a, -n
  14088.         return _rat( pow(a.num,n), pow(a.den,n) )
  14089.     raise ValueError, 'rational raised to non-integer power'
  14090.  
  14091. # -------------------- tests --------------------
  14092. RatTestError = 'RatTestError'
  14093.  
  14094. def test():
  14095.     for args, rep in ( ((0,),'0'), ((0L,),'0L'),
  14096.       ((12L,),'12L'), ((12,),'12'), ((-12L,),'-12L'), ((-12,),'-12'),
  14097.       ((144L,12L),'12L'),
  14098.       ((6,9),'2, 3'), ((-6,9),'-2, 3'), ((6,-9),'-2, 3'),
  14099.       ((-6,-9),'2, 3') ):
  14100.     got = `apply(rat, args)`
  14101.     want = 'rat(' + rep + ')'
  14102.     if got != want:
  14103.         raise RatTestError, ('__repr__', got, want)
  14104.  
  14105.     a = rat(37,8)
  14106.     got = `int(a), long(a), float(a), rat(-float(a))`
  14107.     want = '(4, 4L, 4.625, rat(-37L, 8L))'
  14108.     if got != want:
  14109.     raise RatTestError, ('coercion', got, want)
  14110.  
  14111.     a = rat(1, 10)
  14112.     b = rat(2, 5)
  14113.     l = [a+b, a-b, a*b, a/b, pow(-b, 1/a)]
  14114.     want = [rat(1,2), rat(-3,10), rat(1,25), rat(1,4),
  14115.         rat(1024,pow(5,10)) ]
  14116.     if l != want:
  14117.     raise RatTestError, ('arithmetic', l, want)
  14118.  
  14119.     l.sort()
  14120.     want = [rat(-3,10), rat(1024,pow(5,10)), rat(1,25), rat(1,4), rat(1,2)]
  14121.     if l != want:
  14122.     raise RatTestError, ('sort', l, want)
  14123.  
  14124.     if not a or not b or (a+b)*(a-b)-(pow(a,2)-b*b):
  14125.     raise RatTestError, 'boolean context'
  14126.  
  14127.     d = { rat(2): 'two', rat(-12L,16L): rat(4L,8L) }
  14128.     if d[ pow( d[rat(16,7)*rat(21,-64)], -1 ) ] != 'two':
  14129.     raise RatTestError, 'dictionary'
  14130.  
  14131.     for e in 'rat(1,0)', '5/(rat(4,2)-1/rat(3,6))', 'pow(rat(0),-3)':
  14132.     try:
  14133.         exec( 'print ' + e )
  14134.         raise RatTestError, ('wanted ZeroDivisionError', e)
  14135.     except ZeroDivisionError:
  14136.         pass
  14137.  
  14138.     for args in ( (), (1,1.0), ({},1), ([],), ('ouch',), (1,2,3) ):
  14139.     try:
  14140.         e = apply( rat, args )
  14141.         raise RatTestError, ('wanted TypeError', args)
  14142.     except TypeError:
  14143.         pass
  14144.  
  14145.     a = rat( 1<<30 )
  14146.     a = (a < 1/a)            # should not overflow
  14147.  
  14148.     a = rat( 1L, 1<<30 )
  14149.     if 3+a == a+3 == -(-a-3) == 3-(3-a)+3 == 3-(3+(-a))+3 == \
  14150.       a*2-a+3 == 3*a-2*a-(-3) == \
  14151.       ((a/45L + a)*(45L/a + a)-46)/a*rat(45,46) + 3:
  14152.     pass
  14153.     else:
  14154.     raise RatTestError, 'probably implicit conversion'
  14155.  
  14156.     x = 3.0
  14157.     if x+a == a+x == -(-a-x) == x-(x-a)+x == x-(x+(-a))+x == a-x+2*x:
  14158.     pass
  14159.     else:
  14160.     raise RatTestError, 'probably implicit float conversion'
  14161.  
  14162.     sum = rat(-2L,3)
  14163.     for i in range(1,30):
  14164.     sum = sum + pow(-1,i)*rat(i,i+1)
  14165.     want = rat(-446993812891L, 332727080400L)
  14166.     if sum != want:
  14167.     raise RatTestError, ('sum', want, sum)
  14168.     for i in range(1,30):
  14169.     sum = sum - pow(-1,i)*rat(i,i+1)
  14170.     if sum*3 != -2:
  14171.     raise RatTestError, ('sum not -2/3', sum)
  14172.  
  14173. # test()
  14174.  
  14175. >>> END OF Rat.py
  14176. 
  14177. 
  14178. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  14179.     id AA27619 (5.65b/3.10/CWI-Amsterdam); Fri, 27 Aug 1993 11:39:48 +0200
  14180. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  14181.     id AA03445; Fri, 27 Aug 1993 05:16:32 -0400
  14182. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  14183.     id AA05897; Fri, 27 Aug 93 05:16:30 EDT
  14184. Received: by kaos.ksr.com (4.1/KSR-2.0)
  14185.     id AA08191; Fri, 27 Aug 93 05:16:28 EDT
  14186. Message-Id: <9308270916.AA08191@kaos.ksr.com>
  14187. To: python-list@cwi.nl, allen@ksr.com
  14188. Subject: Rats 2
  14189. Date: Fri, 27 Aug 93 05:16:27 -0400
  14190. From: Tim Peters <tim@ksr.com>
  14191.  
  14192. Added some stuff to the rational-arithmetic module.  Rather than repost,
  14193. I'll just attach the new part of the docs; happy to mail you a copy of
  14194. the module on request (& I'll contribute the whole thing to Guido after
  14195. it settles down).
  14196.  
  14197. The gee-whiz feature is the new approx method, which permits cutting back
  14198. a rational with sharp control over the accuracy of, and/or the number of
  14199. bits used by, the approximation.  E.g., as worked out in the example
  14200. below, you can ask for the most space-efficient rational approximation to
  14201. pi good to at least one part in N (your choice), or the most accurate
  14202. rational approximation to pi that fits in B (your choice) bits; etc.
  14203.  
  14204. think-of-it-as-a-memory-aid-for-335/113<snort>-ly y'rs  - tim
  14205.  
  14206. Tim Peters   tim@ksr.com
  14207. not speaking for Kendall Square Research Corp
  14208.  
  14209.  
  14210. # add support for rat(rational) (a nop)
  14211. # add functions shortrat and longrat
  14212. # add .copy() method
  14213. # add .__abs__() method
  14214. # add .approx(maxbits,minp) method
  14215.  
  14216. ...
  14217.  
  14218. #   rat(rational r)  returns r unchanged
  14219. #
  14220. # Function shortrat takes the same arguments as rat, but always returns a
  14221. # short rat (however, it may overflow!).
  14222. #
  14223. # Function longrat takes the same arguments as rat, but always returns a
  14224. # long rat.
  14225. #
  14226. # If shortrat or longrat are passed an RNO, the RNO itself is changed.
  14227. # However, the mathematical _value_ of the RNO does not change, and
  14228. # neither does its hash value.
  14229. #
  14230. # Method r.copy() returns a copy s, such that r == s.
  14231. #
  14232. # Method r.approx(maxbits, minp) returns a triple (a,n,p).  a is a Rat
  14233. # approximation to r that may take less storage (and hence run faster in
  14234. # subsequent computations, provided that the loss of accuracy can be
  14235. # tolerated).  The approximation is the best possible such that
  14236. #
  14237. # 1) the numerator and denominator each take no more than `maxbits' bits
  14238. #
  14239. # 2) if #1 allows it, the approximation is no worse than 1 part in `minp'
  14240. #    (in other words, abs((a-r)/r) <= 1/minp)
  14241. #
  14242. # `maxbits' and `minp' must be numeric types, and both must be >= 0.
  14243. # Intuitively, minp is a bound on the worst relatively accuracy you're
  14244. # willing to accept, but in no case will you accept more than maxbits
  14245. # bits.  In more detail:
  14246. #
  14247. # A sequence of approximations, a1, a2, a3, ..., r, of increasing storage
  14248. # size and accuracy, is generated internally.  Note that this sequence is
  14249. # finite, since r itself "approximates" r with perfect accuracy.
  14250. #
  14251. # If maxbits == 0, condition #1 is ignored, and if minp > 0 the first
  14252. # approximation in the list meeting the accuracy request is used.
  14253. # If minp == 0, condition #2 is ignored, and if maxbits > 0 the last
  14254. # approximation in the list of size <= maxbits is used.
  14255. # If both are 0, a == r (albeit after extensive computation ...).
  14256. # If both are nonzero, if the first approximation in the list meeting
  14257. # condition #2 also meets #1, that's the one that's used; else the last
  14258. # one in the list meeting #1 is used.
  14259. #
  14260. # As mentioned above, approx returns a triple (a,n,p):
  14261. # a is the rational approximation described above.
  14262. # n is max( number_of_bits_in(a.num), number_of_bits_in(a.den) ).
  14263. # If p is 0, a == r.  Else p is an integer > 0 such that
  14264. #    abs((a-r)/r) <= 1/p
  14265. # (so the approximation is no worse off than 1 part in p).
  14266. #
  14267. # An example should help:
  14268. #
  14269. # >>> import math, Rat
  14270. # >>> p = Rat.rat(math.pi)  # the exact machine value (NOT exact pi!)
  14271. # >>> p  # this may differ on your machine, & some numbers later too
  14272. # rat(884279719003555L, 281474976710656L)
  14273. # >>> p.approx(0,4)  # get an approximation good to 1 part in 4
  14274. # (rat(3L), 2, 22L)
  14275. # >>> # 3/1 is the smallest-size approximation good to 1 part in 4;
  14276. # ... # its biggest piece takes 2 bits (for the numerator, 3);
  14277. # ... # it's actually good to 1 part in 22 (and note that
  14278. # ... # 1/abs((pi-3)/pi) ~= 22.19, so 3/1 is indeed good to 1 part in
  14279. # ... # 22 -- but not to 1 part in 23)
  14280. # ... p.approx(0,1000000)  # get one good to one part in a million
  14281. # (rat(355L, 113L), 9, 11776665L)
  14282. # >>> # the 9-bit rat 335/113 does the trick, and note that
  14283. # ... # 1/abs((pi-355/113)/pi) ~= 11776665.62
  14284. # ... p.approx(0,11776665), p.approx(8,11776665)
  14285. # ((rat(355L, 113L), 9, 11776665L), (rat(22L, 7L), 5, 2484L))
  14286. # >>> # note that the second one could not meet the accuracy request,
  14287. # ... # because the limit on the number of bits would not allow it;
  14288. # ... # note too that 22/7 is in fact the best possible rational
  14289. # ... # approximation with numerator and denominator no more than 8 bits
  14290. # ... p.approx(128,11776666)  # slightly tighter accuracy request
  14291. # (rat(103993L, 33102L), 17, 5436311184L)
  14292. # >>> # 335/113 wasn't quite good enough to meet the accuracy request,
  14293. # ... # and we need 8(!) additional bits to get a better rational
  14294. # ... # approximation (335/113 is indeed a very good approximation)
  14295. # ... p.approx(31,0)  # find best approx that fits in Python ints
  14296. # (rat(1881244168L, 598818617L), 31, 1955598078002080795L)
  14297. # >>> Rat.shortrat(p.approx(31,0)[0])  # proving it does fit <wink>
  14298. # rat(1881244168, 598818617)
  14299. # >>> Rat.shortrat(p.approx(32,0)[0])  # and 32-bit approx doesn't
  14300. # Stack backtrace (innermost last):
  14301. #   File "<stdin>", line 1
  14302. #   File "./Rat.py", line 200
  14303. #     a.num, a.den = int(a.num), int(a.den)
  14304. # ValueError: long int too long to convert
  14305. # >>>
  14306.  
  14307. end of msg
  14308. 
  14309. 
  14310. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  14311.     id AA08736 (5.65b/3.10/CWI-Amsterdam); Sat, 4 Sep 1993 00:41:38 +0200
  14312. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa02834;
  14313.           3 Sep 93 18:41 EDT
  14314. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  14315.     id AA26651; Fri, 3 Sep 1993 17:57:11 -0400
  14316. Date: Fri, 3 Sep 1993 17:57:11 -0400
  14317. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14318. Message-Id: <199309032157.AA26651@elvis.med.Virginia.EDU>
  14319. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  14320. To: python-list@cwi.nl
  14321. Subject: problems with timemodule.c building Python 0.9.9 on IBM AIX 3.2 
  14322.  
  14323. Hi - 
  14324.  
  14325.  I'm trying to build Python 0.9.9 on an IBM RS/6000 AIX 3.2.2 
  14326.  ( I have 0.9.7b built and running fine, including the GL extensions ) 
  14327.  I keep having trouble getting past compiling timemodule.c 
  14328.  I have tried several variations of defines, but I have not yet 
  14329.  found one that works. Has anyone else had any trouble building 0.9.9 ?
  14330.  
  14331.  
  14332.  ( I'll post a followup with more details later, if no one has the 
  14333.   answer off hand, but I've got to run now, and I thought I'ld check 
  14334.   to see if someone know the proper AIX Makefile Configuration.  )
  14335.  
  14336.  
  14337. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  14338. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  14339.  
  14340. 
  14341. 
  14342. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  14343.     id AA17039 (5.65b/3.10/CWI-Amsterdam); Sun, 5 Sep 1993 05:49:37 +0200
  14344. From: Lance Ellinghouse <lance@markv.com>
  14345. X-Mailer: SCO System V Mail (version 3.2)
  14346. To: python-list@cwi.nl
  14347. Subject: tuple handling, but not a tuple...
  14348. Date: Sat, 4 Sep 93 20:48:51 PDT
  14349. Message-Id:  <9309042048.aa02709@hermix.markv.com>
  14350.  
  14351. I have a datatype that I would like to be able to do tuple-unpacking
  14352. on that is NOT a tuple..
  14353.  
  14354. I have a phone number type that I would like to assign as:
  14355.   a = NewPhone()
  14356.   a = (areacode, prefix, number, extension)
  14357.  
  14358. and then be able to do:
  14359.   areacode, prefix, number, extension = a
  14360.  
  14361. Should I just use a tuple? or is there an easy way to have any
  14362. custom type use tuple packing and unpacking?
  14363.  
  14364. Lance Ellinghouse
  14365. lance@markv.com
  14366. 
  14367. 
  14368. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  14369.     id AA05903 (5.65b/3.10/CWI-Amsterdam); Mon, 6 Sep 1993 09:48:36 +0200
  14370. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa09404;
  14371.           6 Sep 93 3:48 EDT
  14372. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  14373.     id AA15933; Mon, 6 Sep 1993 03:48:30 -0400
  14374. Date: Mon, 6 Sep 1993 03:48:30 -0400
  14375. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14376. Message-Id: <199309060748.AA15933@elvis.med.Virginia.EDU>
  14377. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  14378. To: python-list@cwi.nl
  14379. Subject: Re: problems with timemodule.c builing Python 0.9.9 on IBM AIX 
  14380.  
  14381. > Subject: Re:  problems with timemodule.c building Python 0.9.9 on IBM AIX 
  14382.  
  14383. I wrote:
  14384. >  I'm trying to build Python 0.9.9 on an IBM RS/6000 AIX 3.2.2 
  14385. >  ( I have 0.9.7b built and running fine, including the GL extensions ) 
  14386. >  I keep having trouble getting past compiling timemodule.c 
  14387. >  I have tried several variations of defines, but I have not yet 
  14388. >  found one that works. Has anyone else had any trouble building 0.9.9 ?
  14389.  
  14390. On Sep 4, 15:30, John DeGood wrote:
  14391.  
  14392. > I used this successfully on HP-UX 8.07:
  14393. >     ADDCFLAGS=    -DOLDTZ -DNOALTTZD
  14394.  
  14395. Thanks. I tried that and several other combinations.
  14396.  
  14397. > ADDCFLAGS=    -DHAVE_STDLIB -DNOALTTZ -DOLDTZ 
  14398.  
  14399. Worked the best - it only gave one warning on compile that
  14400. there was no definition for floatsleep, and it was changing
  14401. the declaration (from static) to extern. It later bombed
  14402. out on linking when it couldn't find floatsleep. 
  14403.  
  14404. If I tried defining 'unix' or BSD_TIME, so that one of 
  14405. the function definitions would be compiled, I got a 
  14406. pageful of other errors. 
  14407.  
  14408. Finally, I copied the floatsleep definition from the 
  14409. "#ifdef unix" block, into a (new) "#ifdef AIX" block,
  14410. and compiled with:
  14411.  
  14412. >ADDCFLAGS=    -DHAVE_STDLIB -DNOALTTZ -DOLDTZ -DAIX
  14413.  
  14414.  
  14415. And this seems to work. 
  14416.  
  14417.  
  14418. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  14419. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  14420. 
  14421. 
  14422. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  14423.     id AA23416 (5.65b/3.10/CWI-Amsterdam); Tue, 7 Sep 1993 18:32:39 +0200
  14424. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa03445;
  14425.           7 Sep 93 12:32 EDT
  14426. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  14427.     id AA22476; Tue, 7 Sep 1993 12:32:22 -0400
  14428. Date: Tue, 7 Sep 1993 12:32:22 -0400
  14429. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14430. Message-Id: <199309071632.AA22476@elvis.med.Virginia.EDU>
  14431. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  14432. To: python-list@cwi.nl
  14433. Subject: another problem building python 0.9.9 on AIX 3.2.2 
  14434.  
  14435. Well - I got timemodule to compile. 
  14436. The entire build process completes without any errors, and I have
  14437. an executable python 0.9.9 image, but when I try to import posix 
  14438. it get: 
  14439.  ImportError: no module named posix
  14440.  
  14441. I can't run the regression tests because of the error, but
  14442. other things that don't import posix appear to work. 
  14443. ( I was building 0.9.9 so I could use some of the new Class 
  14444.   features, and I was playing around with these for an evening
  14445.   before I decided to run the tests before trying to rebuild 
  14446.   with X11 and GL support. ) 
  14447.  
  14448. posixmodule.c  compiles without any error messages and 
  14449. it is linked into the image. 
  14450.  
  14451. my ADDCFLAGS are: 
  14452. ADDCFLAGS=      -DHAVE_STDLIB -DNOALTTZ -DOLDTZ -DAIX
  14453.  
  14454. ( The AIX is defined for my kludge to get timemodule to compile - 
  14455.   see previous message. ) 
  14456.  
  14457.  
  14458. - Steve Majewski 
  14459. 
  14460. 
  14461. Received: from ansjovis.cwi.nl by charon.cwi.nl with SMTP
  14462.     id AA23791 (5.65b/3.10/CWI-Amsterdam); Tue, 7 Sep 1993 18:40:48 +0200
  14463. Received: by ansjovis.cwi.nl with SMTP
  14464.     id AA17988 (5.65b/3.8/CWI-Amsterdam); Tue, 7 Sep 1993 18:40:47 +0200
  14465. Message-Id: <9309071640.AA17988=sjoerd@ansjovis.cwi.nl>
  14466. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14467. Cc: python-list@cwi.nl
  14468. Subject: Re: another problem building python 0.9.9 on AIX 3.2.2 
  14469. In-Reply-To: Your message of Tue, 07 Sep 1993 12:32:22 -0400.
  14470.              <199309071632.AA22476@elvis.med.Virginia.EDU> 
  14471. Date: Tue, 07 Sep 1993 18:40:45 +0200
  14472. From: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
  14473.  
  14474. On Tue, Sep 7 1993 "Steven D. Majewski" wrote:
  14475.  
  14476. > Well - I got timemodule to compile. 
  14477. > The entire build process completes without any errors, and I have
  14478. > an executable python 0.9.9 image, but when I try to import posix 
  14479. > it get: 
  14480. >  ImportError: no module named posix
  14481. > I can't run the regression tests because of the error, but
  14482. > other things that don't import posix appear to work. 
  14483. > ( I was building 0.9.9 so I could use some of the new Class 
  14484. >   features, and I was playing around with these for an evening
  14485. >   before I decided to run the tests before trying to rebuild 
  14486. >   with X11 and GL support. ) 
  14487. > posixmodule.c  compiles without any error messages and 
  14488. > it is linked into the image. 
  14489. > my ADDCFLAGS are: 
  14490. > ADDCFLAGS=      -DHAVE_STDLIB -DNOALTTZ -DOLDTZ -DAIX
  14491. > ( The AIX is defined for my kludge to get timemodule to compile - 
  14492. >   see previous message. ) 
  14493. > - Steve Majewski 
  14494.  
  14495. Apparently USE_POSIX didn't get defined in config.c.  You can have a
  14496. look there to see under which circumstances USE_POSIX is defined.  My
  14497. guess is that "unix" is not defined.  I suppose that the ifdefs in
  14498. config.c should be improved, but for the time being you can try
  14499. defining "unix" yourself, or change config.c to check for another
  14500. value.
  14501.  
  14502. Sjoerd Mullender
  14503. CWI, dept. CST, Kruislaan 413, 1098 SJ Amsterdam, Netherlands
  14504. email: Sjoerd.Mullender@cwi.nl        fax:   +31 20 592 4199
  14505. phone: +31 20 592 4127            telex: 12571 mactr nl
  14506. 
  14507. 
  14508. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  14509.     id AA28411 (5.65b/3.10/CWI-Amsterdam); Tue, 7 Sep 1993 21:00:29 +0200
  14510. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa28893;
  14511.           7 Sep 93 15:00 EDT
  14512. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  14513.     id AA25297; Tue, 7 Sep 1993 15:00:12 -0400
  14514. Date: Tue, 7 Sep 1993 15:00:12 -0400
  14515. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14516. Message-Id: <199309071900.AA25297@elvis.med.Virginia.EDU>
  14517. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  14518. To: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
  14519. Subject: config.c, Makefile, Configure.py, etc. ( was: problem ... on AIX ) 
  14520. Cc: python-list@cwi.nl, Guido.van.Rossum@cwu.nl
  14521.  
  14522. On Sep 7, 18:40, Sjoerd Mullender wrote:
  14523. > Apparently USE_POSIX didn't get defined in config.c.  You can have a
  14524. > look there to see under which circumstances USE_POSIX is defined.  My
  14525. > guess is that "unix" is not defined.  I suppose that the ifdefs in
  14526. > config.c should be improved, but for the time being you can try
  14527. > defining "unix" yourself, or change config.c to check for another
  14528. > value.
  14529.  
  14530. Thanks. That was the problem. 
  14531. But the other problem is that defining unix (globally) makes timemodule.c 
  14532. unable to compile. So (one more kludge!) I defined it in the makefile
  14533. here:
  14534.  
  14535. >config.o:    config.c Makefile libpython.a 
  14536. >        $(COMPILE) $(CONFIGDEFS) $(CONFIGINCLS) -Dunix $*.c
  14537.  
  14538. and "import posix" works and: 
  14539.  
  14540. >make test
  14541. >        PYTHONPATH=../lib ./python -c 'import autotest'
  14542. >All tests OK.
  14543.  
  14544.  
  14545. Note: unix is not automatically defined for AIX, so I didn't 
  14546. undef it for timemodule.c 
  14547.  
  14548.  
  14549. Is there anyone else out there building/using python on AIX ? 
  14550. ( I know there are someother UVA folks on this list. ) 
  14551.  
  14552.  
  14553. Is anyone else running into problems with make or ./Configure.py 
  14554. for 0.9.9 ? 
  14555.  
  14556. Most of the problems I've run into are minor, but I'ld like to 
  14557. help Guido sort them out before he gets to the 1.0 release. 
  14558.  
  14559. The other glitch I ran into ( besides posix and the timemodule ) 
  14560. was that, when I did NOT select X11 support in ./Configure.py, 
  14561. the Makefile did not comment out those lines properly, i.e. :
  14562.  
  14563. >#XT_OBJ=    Xtmodule.o Xttypes.o GCobject.o Fontobject.o \
  14564. >        widgetobject.o wclassobject.o
  14565. >
  14566. >#XT_SRC=    Xtmodule.c Xttypes.c GCobject.c Fontobject.c \
  14567. >        widgetobject.c wclassobject.c
  14568.  
  14569. which 'make' didn't much care for, instead of:
  14570.  
  14571. >#XT_OBJ=    Xtmodule.o Xttypes.o GCobject.o Fontobject.o \
  14572. >#        widgetobject.o wclassobject.o
  14573. >
  14574. >#XT_SRC=    Xtmodule.c Xttypes.c GCobject.c Fontobject.c \
  14575. >#        widgetobject.c wclassobject.c
  14576.  
  14577.  
  14578.  
  14579.  
  14580. FY( Guido's mostly )I:
  14581.  
  14582. A long time ago, Guido asked me (and the list, I think) what 
  14583. symbols were automatically defined in AIX. I didn't answer at
  14584. the time, because I wasn't sure myself. It turns out that 
  14585. most of the "automatic" definitions are defined by a configure
  14586. file ( /etc/xlc.cfg ), and are different according to which 
  14587. compiler 'alias' is used ( xlc, cc, c89, bsdcc ). This file
  14588. is user configurable ( UVA has added 'bsdcc' to the standard 
  14589. file - it is in the xlc manual, but not in the standard cfg file.)
  14590. "_AIX" appears to be the "standard" predefined symbol. 
  14591. My 'gcc' also appears to define "_AIX" , but I don't know 
  14592. if this is standard, or has been modified here at UVA. 
  14593. ( And the RT C compiler predefines "AIX" and "unix" , but 
  14594. not "_AIX" !  ) 
  14595.  
  14596.  
  14597. I have seen a lot of portable Makefile's set ARCH via `uname` - 
  14598. ( which seems to be more standard than SunOS `arch' ) and then
  14599. use that to define it explicitly in CFLAGS. ( Which is how I've 
  14600. gotten into the habit of often using "#ifdef aix" instead of 
  14601. the "standard" "#ifdef _AIX" . 
  14602.  
  14603. ( If you want to know why something compiles under 'cc', but not c89 )
  14604. Here is my /etc/xlc.cfg which is (I think) the same as the standard
  14605. AIX 3.2.2 distribution except for the addition of 'bsdcc'. language
  14606. level causes some other defines ( e.g. "-qlanglevl=extended" causes 
  14607. __EXTENDED__ to be defined. ) and also changes the language accepted
  14608. by the compiler. 
  14609.  
  14610. * @(#) xlc.cfg 1.2 12/19/91 19:30:55
  14611. *
  14612. * COMPONENT_NAME: (CC) AIX XL C Compiler/6000
  14613. *
  14614. * FUNCTIONS: C Configuration file
  14615. *
  14616. * ORIGINS: 27
  14617. *
  14618. * (C) COPYRIGHT International Business Machines Corp. 1989, 1990, 1991
  14619. * All Rights Reserved
  14620. * Licensed Materials - Property of IBM
  14621. *
  14622. * US Government Users Restricted Rights - Use, duplication or
  14623. * disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  14624. *
  14625.  
  14626. * standard c compiler
  14627. xlc:    use        = DEFLT
  14628.         crt        = /lib/crt0.o
  14629.         mcrt       = /lib/mcrt0.o
  14630.         gcrt       = /lib/gcrt0.o
  14631.         libraries  = -lc
  14632.         proflibs   = -L/lib/profiled,-L/usr/lib/profiled
  14633.         options    = -H512,-T512,-D_ANSI_C_SOURCE,-qansialias
  14634.  
  14635. * standard c compiler aliased as cc
  14636. cc:     use        = DEFLT
  14637.         crt        = /lib/crt0.o
  14638.         mcrt       = /lib/mcrt0.o
  14639.         gcrt       = /lib/gcrt0.o
  14640.         libraries  = -lc
  14641.         proflibs   = -L/lib/profiled,-L/usr/lib/profiled
  14642.         options    = -H512,-T512,-qlanglvl=extended,-qnoro
  14643.  
  14644.  
  14645. * standard c compiler aliased as c89
  14646. c89:    use        = DEFLT
  14647.         crt        = /lib/crt0.o
  14648.         mcrt       = /lib/mcrt0.o
  14649.         gcrt       = /lib/gcrt0.o
  14650.         libraries  = -lc
  14651.         proflibs   = -L/lib/profiled,-L/usr/lib/profiled
  14652.         options    = -H512,-T512,-D_ANSI_C_SOURCE,-qansialias
  14653.  
  14654.  
  14655. * common definitions
  14656. DEFLT:  xlc        = /usr/lpp/xlc/bin/xlcentry
  14657.         as         = /bin/as
  14658.         ld         = /bin/ld
  14659.         options    = -D_IBMR2,-D_AIX,-bhalt:4
  14660.         ldopt      = "b:o:e:u:R:H:Y:Z:L:T:A:V:k:j:"
  14661.  
  14662. * bsdcc setup from the porting guide
  14663. bsdcc:  use        = DEFLT
  14664.         crt        =/lib/crt0.o
  14665.         mcrt       =/lib/mcrt0.o
  14666.         gcrt       =/lib/gcrt0.o
  14667.         libraries  = -lbsd, -lc
  14668.         proflibs   = -L/lib/profiled,-L/usr/lib/profiled
  14669.         options    = -H512,-T512,-qlanglvl=extended,-qnoro,-D_BSD,-D_NONSTD_TYPES,-D_NO_PROTO,-D_BSD_INCLUDES,-bnodelcsect,-U__STR__,-U__MATH__
  14670.  
  14671.  
  14672. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  14673. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  14674. 
  14675. 
  14676. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  14677.     id AA29961 (5.65b/3.10/CWI-Amsterdam); Tue, 7 Sep 1993 22:01:47 +0200
  14678. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa09776;
  14679.           7 Sep 93 16:01 EDT
  14680. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  14681.     id AA22402; Tue, 7 Sep 1993 16:01:21 -0400
  14682. Date: Tue, 7 Sep 1993 16:01:21 -0400
  14683. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14684. Message-Id: <199309072001.AA22402@elvis.med.Virginia.EDU>
  14685. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  14686. To: python-list@cwi.nl
  14687. Subject: another change for compiling python0.9.9 on AIX ( Fontmodule.c/X11 ) 
  14688.  
  14689.  
  14690. The AIX C compiler does not appear to like this pair of
  14691. declarations in Fontobject.c ( when compiling with X11 option ):
  14692.  
  14693. >extern typeobject Fonttype; /* Really static forward */
  14694.  [ ... ]
  14695. >static typeobject Fonttype = { 
  14696.  [ ... ]
  14697.  
  14698. and complains about the redefinition. 
  14699.  
  14700. substitute the following. 
  14701.  
  14702. #ifdef _AIX
  14703. static typeobject Fonttype; /* Really static FORWARD */
  14704. #else
  14705. extern typeobject Fonttype; /* Really STATIC forward */
  14706. #endif
  14707.  
  14708.  
  14709. - Steve Majewski 
  14710. 
  14711. 
  14712. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  14713.     id AA07399 (5.65b/3.10/CWI-Amsterdam); Wed, 8 Sep 1993 09:35:46 +0200
  14714. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa04033;
  14715.           8 Sep 93 3:35 EDT
  14716. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  14717.     id AA12912; Wed, 8 Sep 1993 03:35:37 -0400
  14718. Date: Wed, 8 Sep 1993 03:35:37 -0400
  14719. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14720. Message-Id: <199309080735.AA12912@elvis.med.Virginia.EDU>
  14721. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  14722. To: python-list@cwi.nl
  14723. Subject: Thoughts and proposals about types and classes.
  14724.  
  14725.  
  14726.  
  14727. I've been Reading the rational class posted by Tim Peters and some of the new
  14728. Class documentation and trying out some of the new (or newly documented)
  14729. features. Here are a few proposals for consideration. 
  14730.  
  14731.  
  14732. Long ago, I had a few gripes about the python type system, but at that
  14733. time they were more theoretical than practical. All of the new Class 
  14734. capabilities now make that complaint more practical:
  14735. The python type system is too narrow for builtin types, and too broad
  14736. for classes and instances ( where *everything* is <type 'class'> or
  14737. <type 'instance>' ). 
  14738.  
  14739.  
  14740. For example: with numeric types, we are often not interested in their
  14741. actual type - that's why there is type coercion. We just what to check
  14742. that an argument is, in fact, a numeric type of some sort. For builtin
  14743. types, we can check: 
  14744.   "if type( arg ) in ( type(0), type( 0L ), type( 0.0 ) ) :"
  14745. But this does not extend to user written classes like Complex or Rat. 
  14746.  
  14747. One approach would be to create a new convention that all numeric 
  14748. classes ( That is all classes that define methods for ( __add__, __sub__,
  14749. ..., __neg__, ... , __int__, __long__, __float__ ) - all the standard
  14750. numeric methods, and where the semantics of those methods are something
  14751. that would be considered numeric ( NOT '+' for string concatenation, for
  14752. example. ) define an attribute "__isnumeric__ " .  A function: 'isnumeric',
  14753. would check for either builtin numeric types or class instances with
  14754. __isnumeric__ defined. This would probably be a builtin, but a python
  14755. version is:
  14756.  
  14757.  
  14758.  
  14759. --------------begin-----------
  14760. #!/usr/local/bin/python
  14761. #
  14762. # the version kludge is because I have msdos version 0.9.8 at home, 
  14763. #  unix version 0.9.7b installed on Sun + AIX, and 0.9.9 experimentally
  14764. # in use under AIX.
  14765. #
  14766.  
  14767. import string
  14768. import sys
  14769.  
  14770. attr = '_isnumeric_'              #  '__isnumeric__' is Read Only
  14771.  
  14772.  
  14773. ver = string.split( sys.version )[0]
  14774. if ( ver >= '0.9.9' ):
  14775.    def isnumeric(obj):
  14776.     if type(obj) in ( type(0), type(0L), type(0.0) ) :
  14777.         return 1
  14778.     elif hasattr( obj, attr ) : 
  14779.         return getattr( obj, attr )
  14780.     else:
  14781.         return 0
  14782. else:
  14783.    def isnumeric(obj):
  14784.     if type(obj) in ( type(0), type(0L), type(0.0) ) :
  14785.         return 1
  14786.     try:
  14787.         return getattr( obj, attr )
  14788.     except ( NameError, TypeError ):
  14789.         return 0
  14790.  
  14791.  
  14792. def number( obj ):
  14793.     if isnumeric( obj ):
  14794.         print `obj` + ' is a number.'
  14795.     else:
  14796.         print `obj` + ' is NOT a number.'
  14797.  
  14798.  
  14799.  
  14800.  
  14801. def test():
  14802.     class TestNumb:
  14803.         _isnumeric_ = 0
  14804.         def init(self):
  14805.             self._isnumeric_ = 1
  14806.             return self
  14807.     N = TestNumb().init() 
  14808.  
  14809.     number( 1 )
  14810.     number( 1L )
  14811.     number( 1000.0 )
  14812.     number( 'this string' )
  14813.     number( type( 0L ) )
  14814.     number( TestNumb )
  14815.     number( N )
  14816.  
  14817.  
  14818. test()
  14819.  
  14820.  
  14821. -------------end-------------
  14822.  
  14823. I'm not sure that I digested and understood all of the previous discussion
  14824. between Jaap and Guido about instance vs class attributes. From looking
  14825. at some of the 0.9.9 changes, it looks as if some of the semantics may
  14826. have been changed in the light of that discussion. I may be wrong. 
  14827.  
  14828.  
  14829. But this brings up the question of whether the __numeric__ attribute
  14830. should be a class attribute or an instance attribute. It is the instance
  14831. which is numeric, NOT the class - but it doesn't look quite right to
  14832. create a new instance attribute ( with the identical value ) for each
  14833. instance. I suppose the solution is to make it a function/method, 
  14834. which returns 0 or 1, rather than a value attribute. Then it is in
  14835. the class namespace but responds as an instance method. 
  14836.  
  14837.  
  14838. The same conventions could be followed for '__issequence__' and
  14839. '__ismapping__'  ( It is the ability to override operators like
  14840. '+' or `[indx]' or  '[i:j]' for user defined types that makes 
  14841. the limits of type() more obvious. ) 
  14842.  
  14843. If the typeing of builtin's is too narrow, then the typing
  14844. of user instances is too broad. Everything is '<type class>'
  14845. or '<type instance>'. ( I guess I don't really have a problem
  14846. with '<type class>', but '<type 'instance'>' is not very useful.) 
  14847.  
  14848.  
  14849. One idea would be to make 'type' of user instances programmable
  14850. just like 'repr'.  If I want two classes to be "equivalent" , then
  14851. I just define their type strings to be identical. 
  14852.  
  14853.  
  14854. How fixed is the notion that type(thing) is a single value? 
  14855. Perhaps type should be a 2-tuple of ( most-restrictive-type, least-
  14856. restrictive-type ) 
  14857.  
  14858.     type( 0 )     ==> ( <type 'int'>, <type 'numeric'> ) 
  14859.     type( 1.0 )     ==> ( <type 'float'> , <type 'numeric'> )
  14860.     type( [] )     ==> ( <type 'list' >, <type 'sequence' > )
  14861.     type( (1,2) )    ==> ( <type 'tuple' >, <type 'sequence' > )
  14862.  
  14863. Since equality comparison works on tuples, "type(agr) == type( [] )"
  14864. would still work. But  "type(type(None))" would no longer be 
  14865. <type 'type'>, it would become '<type 'tuple' > instead. 
  14866.  
  14867. Also: when you try to fit user instances into this scheme, they are:
  14868.  (extremely) generically: instances 
  14869.  specifically: instances of some Class
  14870.  (moderately) generically: possibly of some type "family" 
  14871.         ( numeric, sequence, iosource, iosink, ... ) 
  14872.  
  14873.  
  14874. Maybe there should be functions 'type()' and 'typefamily()' ? 
  14875. Where typefamily() => number | sequence | mapping, for builtins,
  14876. and whatever __typefamily__(self)  returns for user defined 
  14877. instances, or type(self) if undefined. 
  14878.  
  14879.  
  14880. More ambitious perhaps, might be an entire type hierarchy, with
  14881. base class types automatically added to the list: 
  14882.  
  14883.     "if type(thing) in typeset( object ): "
  14884.  
  14885. where typeset(obj) yields a tuple built from object's class +
  14886. base class type strings ( something more specific than: )
  14887. + <type 'instance'> OR a builtin tuple ( for example: 
  14888. ( <type 'int'>, <type 'number'> ) )
  14889.  
  14890. ( Actually - that doesn't sound so bad. It require one 
  14891.  more builtin function + one more attribute for both 
  14892.  builtin and user defined objects, it doesn't break
  14893.  anything that uses 'type()', and it's general enough
  14894.  to make "type inheritance" usable. What do you think? )
  14895.  
  14896. What sort of approach would make the best fit with python? 
  14897.  
  14898.  
  14899.  
  14900.                                                                  
  14901.  
  14902. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  14903. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  14904.  
  14905. 
  14906. 
  14907. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  14908.     id AA10225 (5.65b/3.10/CWI-Amsterdam); Wed, 8 Sep 1993 11:30:52 +0200
  14909. Received: by schelvis.cwi.nl with SMTP
  14910.     id AA21144 (5.65b/3.8/CWI-Amsterdam); Wed, 8 Sep 1993 11:30:51 +0200
  14911. Message-Id: <9309080930.AA21144=jack@schelvis.cwi.nl>
  14912. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14913. Cc: python-list@cwi.nl
  14914. Subject: Re: another problem building python 0.9.9 on AIX 3.2.2 
  14915. In-Reply-To: Message by "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> ,
  14916.          Tue, 7 Sep 1993 12:32:22 -0400 , <199309071632.AA22476@elvis.med.Virginia.EDU> 
  14917. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  14918. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  14919. X-Last-Band-Seen: Kliek, Lyres (Sleepin, 2-9)
  14920. X-Mini-Review: Groovy sixties, man....
  14921. Date: Wed, 08 Sep 1993 11:30:51 +0200
  14922. From: Jack Jansen <Jack.Jansen@cwi.nl>
  14923.  
  14924. Steve, have you looked at your sys.path? If that looks correctly, you
  14925. could try something like:
  14926. import sys
  14927.  
  14928. for pn in sys.path:
  14929.     fn = pn + '/posix.py'
  14930.     try:
  14931.          fp = open(fn, 'r')
  14932.      print 'Success with', fn
  14933.     except:
  14934.          print 'failed with', fn
  14935.  
  14936. At least that will tell you that the files really exist, and are
  14937. readable to python.
  14938. --
  14939. Jack Jansen        | If I can't dance I don't want to be part of
  14940. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  14941. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  14942. 
  14943. 
  14944. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  14945.     id AA10317 (5.65b/3.10/CWI-Amsterdam); Wed, 8 Sep 1993 11:35:01 +0200
  14946. Received: by schelvis.cwi.nl with SMTP
  14947.     id AA21197 (5.65b/3.8/CWI-Amsterdam); Wed, 8 Sep 1993 11:35:00 +0200
  14948. Message-Id: <9309080935.AA21197=jack@schelvis.cwi.nl>
  14949. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14950. Cc: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>, python-list@cwi.nl,
  14951.         Guido.van.Rossum@cwu.nl
  14952. Subject: Re: config.c, Makefile, Configure.py, etc. ( was: problem ... on AIX ) 
  14953. In-Reply-To: Message by "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> ,
  14954.          Tue, 7 Sep 1993 15:00:12 -0400 , <199309071900.AA25297@elvis.med.Virginia.EDU> 
  14955. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  14956. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  14957. X-Last-Band-Seen: Kliek, Lyres (Sleepin, 2-9)
  14958. X-Mini-Review: Groovy sixties, man....
  14959. Date: Wed, 08 Sep 1993 11:34:59 +0200
  14960. From: Jack Jansen <Jack.Jansen@cwi.nl>
  14961.  
  14962. ok, ok, please ignore my previous message. I had temporarily slipped
  14963. my mind that posix is a builtin module. As Sjoerd just said "Zeg Jack,
  14964. wat stuur jij nou voor onzin naar de mailinglist??":-)
  14965. --
  14966. Jack Jansen        | If I can't dance I don't want to be part of
  14967. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  14968. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  14969. 
  14970. 
  14971. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  14972.     id AA03157 (5.65b/3.10/CWI-Amsterdam); Wed, 8 Sep 1993 20:08:53 +0200
  14973. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  14974.     id AA01516; Wed, 8 Sep 93 11:09:44 -0700
  14975. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  14976.     id AA27827; Wed, 8 Sep 93 11:13:56 -0700
  14977. Received: by ushqgw.sequent.com with Microsoft Mail
  14978.     id <2C8E1FD8@ushqgw.sequent.com>; Wed, 08 Sep 93 11:09:28 PDT
  14979. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  14980. To: python-list <python-list@cwi.nl>,
  14981.         "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  14982. Subject: RE: Thoughts and proposals about types and classes.
  14983. Date: Wed, 08 Sep 93 11:07:00 PDT
  14984. Message-Id: <2C8E1FD8@ushqgw.sequent.com>
  14985. Encoding: 40 TEXT
  14986. X-Mailer: Microsoft Mail V3.0
  14987.  
  14988.  
  14989.  
  14990. Just a quick comment on Steve's message about type().
  14991.  
  14992. I feel that Python may be headed for a rat-hole. Currently we are mixing the 
  14993. procedural-based paradigm with the OO paradigm. To implement procedures, 
  14994. such as len(), we add the __len__ method to user classes. I understand the 
  14995. reasons for doing so (speed, complexity, space, attainable), but it seems 
  14996. backwards. Even by not opening up the builtin objects, it seems more 
  14997. intuitive to implement all functions as methods ('some_string'.len()), at 
  14998. the expense of space (backwards compatibility would be a breeze). For user 
  14999. objects, Python should provide a set of base classes to have a more common 
  15000. framework to start from.
  15001.  
  15002. Steve's problem has been solved in Smalltalk, where the class hierarchy 
  15003. spells out one aspect of the type() functionality ('isKindOf' method), and 
  15004. generalization addresses the other aspect ('species' method). I'm not saying 
  15005. that this is *the* solution, but it is certainly more intuitive.
  15006.  
  15007. Comments?
  15008.  
  15009. | I'm not sure that I digested and understood all of the previous | 
  15010. discussion
  15011. | between Jaap and Guido about instance vs class attributes. From | looking
  15012. | at some of the 0.9.9 changes, it looks as if some of the | semantics may
  15013. | have been changed in the light of that discussion. I may be wrong.
  15014.  
  15015. Just to clarify the current behavior of Python (0.9.9) w.r.t. class vs. 
  15016. instance variables and methods:
  15017.  
  15018.      o You can use either instance variables or class variable.
  15019.        When you use class variables, you can refer to them in
  15020.        any subclass and the variables will be looked up by
  15021.        searching the base classes (i.e.
  15022.        instance.__class__.variable)
  15023.      o Only instance and unbound methods are supported. Class
  15024.        methods are impossible in the current implementation.
  15025.  
  15026.  
  15027.      -Jaap-
  15028. 
  15029. 
  15030. Received: from trevnx.BIO.dfo.ca by charon.cwi.nl with SMTP
  15031.     id AA06866 (5.65b/3.10/CWI-Amsterdam); Wed, 8 Sep 1993 21:52:34 +0200
  15032. Received: by trevnx.bio.dfo.ca (NX5.67c/NX3.0M)
  15033.     id AA14806; Wed, 8 Sep 93 16:52:31 -0300
  15034. Date: Wed, 8 Sep 93 16:52:31 -0300
  15035. From: George White 6-8509 <gwhite@trevnx.bio.dfo.ca>
  15036. Message-Id: <9309081952.AA14806@trevnx.bio.dfo.ca>
  15037. To: python-list@cwi.nl
  15038. Subject: Python 0.9.9 runs on NeXT (black, 3.0, mouse-X)
  15039.  
  15040. Like many people, I'm looking at tools to help my Internet grazing,
  15041. provide better documentation, etc.  
  15042.  
  15043. It wasn't hard getting stdwin 0.9.8 and python 0.9.9 to run under NS
  15044. 3.0.  I used Mouse-X libraries (no Motif) but run X clients on an NCD
  15045. X-terminal rather than the Mouse-X server.
  15046.  
  15047. Compilation details:
  15048.  
  15049. I followed the suggestion to make a basic version of python in order
  15050. to use the interactive configuration.  The hardest part was remembering
  15051. the "-m" flag to permit linking with the provided version of strtol.c
  15052. because the first attempt (using NeXT's strtol) didn't pass the "make test"
  15053. tests.
  15054.  
  15055. $ grep "^[^#]" Makefile
  15056. CFLAGS=         $(THREAD_USE) $(ADDCFLAGS) $(X11_INCL)
  15057. ARCH=       next
  15058. CC=             cc
  15059. AR=             ar
  15060. ADDCFLAGS=
  15061. WAITDEF=        -DNO_WAITPID
  15062. LIBMATH=        -lm
  15063. DESTDIR=/usr/local
  15064. BINDESTDIR=$(DESTDIR)/bin
  15065. BINDEST=$(BINDESTDIR)/python
  15066. MANDESTDIR=$(DESTDIR)/man/man1
  15067. MANDEST=$(MANDESTDIR)/python.1
  15068. LIBDESTDIR=$(DESTDIR)/lib
  15069. LIBDEST=$(LIBDESTDIR)/python
  15070. DOCDEST=$(LIBDEST)/doc
  15071. DEMODEST=$(LIBDEST)/demo
  15072. DEFPYTHONPATH=  .:$(LIBDEST):$(LIBDEST)/$(ARCH)
  15073. STRERROR_SRC=  strerror.c
  15074. STRERROR_OBJ=  strerror.o
  15075. FMOD_SRC=  fmod.c
  15076. FMOD_OBJ=  fmod.o
  15077. STRTOL_SRC=  strtol.c
  15078. STRTOL_OBJ=  strtol.o
  15079. GETCWD_SRC=  getcwd.c
  15080. GETCWD_OBJ=  getcwd.o
  15081. SIGTYPEDEF=     -DSIGTYPE=int
  15082. BSDTIMEDEF=     -DBSD_TIME
  15083. TIMESDEF=       -DDO_TIMES
  15084. RE_USE= -DUSE_REGEX
  15085. RE_SRC= regexpr.c regexmodule.c
  15086. RE_OBJ= regexpr.o regexmodule.o
  15087. LIBREADLINE=    /usr/local/lib/libreadline.a
  15088. LIBTERMCAP=     -ltermcap
  15089. RL_USE =        -DUSE_READLINE
  15090. RL_LIBS=        $(LIBREADLINE)
  15091. RL_LIBDEPS=     $(LIBREADLINE)
  15092. ADDLIBS=-m # so that we can use strtol.c
  15093. STDWINDIR=      ../../stdwin
  15094. LIBSTDWIN=      $(STDWINDIR)/Build/$(ARCH)/x11/lib/lib.a
  15095. LIBX11 =        -lX11
  15096. STDW_INCL=      -I$(STDWINDIR)/H
  15097. STDW_USE=       -DUSE_STDWIN
  15098. STDW_LIBS=      $(LIBSTDWIN)
  15099. STDW_LIBDEPS=   $(LIBSTDWIN)
  15100. STDW_SRC=       stdwinmodule.c
  15101. STDW_OBJ=       stdwinmodule.o
  15102. X11_USE=        -DUSE_X11
  15103. X11_INCL=       
  15104. X11_LIBDIRS=    
  15105. XT_USE=         -DUSE_XT
  15106. XT_LIBS=        -lXmu -lXt -lX11 -lXext
  15107. XT_OBJ= Xtmodule.o Xttypes.o GCobject.o Fontobject.o \
  15108.                 widgetobject.o wclassobject.o
  15109. XT_SRC= Xtmodule.c Xttypes.c GCobject.c Fontobject.c \
  15110.                 widgetobject.c wclassobject.c
  15111. EDITRES_USE=    -DUSE_EDITRES
  15112. XAW_USE=        -DUSE_XAW
  15113. XAW_LIBS=       -lXaw
  15114. XAW_OBJ=        Xawmodule.o
  15115. XAW_SRC=        Xawmodule.c
  15116. HTML_USE=       -DUSE_HTML
  15117. HTML_OBJ=       HTMLmodule.o
  15118. HTML_SRC=       HTMLmodule.c
  15119. HTML_LIBS=      /usr/local/lib/libhtmlw.a
  15120. X11_USE=        $(XT_USE) $(XAW_USE) $(XM_USE) $(GLX_USE) $(HTML_USE)
  15121. X11_LIBS=       $(X11_LIBDIRS) \
  15122.                 $(XAW_LIBS) $(XM_LIBS) $(GLX_LIBS) $(HTML_LIBS) $(XT_LIBS)
  15123. X11_OBJ=        $(XT_OBJ) $(XAW_OBJ) $(XM_OBJ) $(GLX_OBJ) $(HTML_OBJ)
  15124. X11_SRC=        $(XT_SRC) $(XAW_SRC) $(XM_SRC) $(GLX_SRC) $(HTML_SRC)
  15125. FCNTL_USE=      -DUSE_FCNTL
  15126. FCNTL_SRC=      fcntlmodule.c
  15127. FCNTL_OBJ=      fcntlmodule.o
  15128. FCNTL_LIBS=
  15129. FCNTL_LIBDEPS=
  15130. DBM_USE=        -DUSE_DBM
  15131. DBM_SRC=        dbmmodule.c
  15132. DBM_OBJ=        dbmmodule.o
  15133. DBM_LIBS=
  15134. DBM_LIBDEPS=
  15135. STROP_USE=      -DUSE_STROP
  15136. STROP_SRC=      stropmodule.c
  15137. STROP_OBJ=      stropmodule.o
  15138. STROP_LIBS=
  15139. STROP_LIBDEPS=
  15140. IMAGEOP_USE=    -DUSE_IMAGEOP
  15141. IMAGEOP_SRC=    imageopmodule.c
  15142. IMAGEOP_OBJ=    imageopmodule.o
  15143. IMAGEOP_LIBS=
  15144. IMAGEOP_LIBDEPS=
  15145. ARRAY_USE=      -DUSE_ARRAY
  15146. ARRAY_SRC=      arraymodule.c
  15147. ARRAY_OBJ=      arraymodule.o
  15148. ARRAY_LIBS=
  15149. ARRAY_LIBDEPS=
  15150.  
  15151. A few hacks in posixmodule.c:
  15152.  
  15153. #ifdef NeXT
  15154. #define mode_t int
  15155. #define NO_UNAME
  15156. #define HZ 60
  15157. typedef int clock_t;
  15158. #endif /* NeXT */
  15159.  
  15160.  
  15161. So far I have used the www client, ibrowse, and texi2html as well
  15162. as a bit of interactive messing around with no serious unpleasantness.  
  15163. Python certainly looks like something I will use.  Thanks to 
  15164. Guido Rossum and crew.
  15165.  
  15166. /George White <GWhite@BIOnet.BIO.DFO.ca> Bedford Inst. of Oceanography
  15167. 
  15168. 
  15169. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  15170.     id AA06940 (5.65b/3.10/CWI-Amsterdam); Wed, 8 Sep 1993 21:54:29 +0200
  15171. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa00686;
  15172.           8 Sep 93 15:54 EDT
  15173. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  15174.     id AA20950; Wed, 8 Sep 1993 15:54:04 -0400
  15175. Date: Wed, 8 Sep 1993 15:54:04 -0400
  15176. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  15177. Message-Id: <199309081954.AA20950@elvis.med.Virginia.EDU>
  15178. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  15179. To: python-list@cwi.nl
  15180. Subject: a buffered input stream class 
  15181.  
  15182.  
  15183. This is a somewhat awkward example of an input stream class.
  15184.  
  15185. The first half was written for a practical purpose.
  15186. The main function I needed was the readuntil( delimiter ) 
  15187. method. I'm sure that some of you would just slurp in 
  15188. the whole file and then process it as a string. Well - 
  15189. I may need to process vary large files, I may need to
  15190. test it on smaller files on my 640K PC at home, but mostly, 
  15191. I would like to keep a sequential flow to the processing. 
  15192. Still, for that requirement, it could be simpler (and faster),
  15193. but I wanted to play around with python classes. 
  15194.  
  15195. Which leads me to comment on the 2nd half - which was tacked
  15196. on later as an experiment. One result of the experiment was
  15197. discovering that my attempt at a "string index" for a sequence
  15198. didn't work : the index can only be an int! 
  15199.  
  15200. Initially, I was going to add a version of readuntil where delimiter
  15201. could be a regexp. Then, after I started playing around with getslice,
  15202. I thought it would be neat to be able to write "stream[0:regexp]" 
  15203. and have it return from the current position thru till the end of
  15204. the regexp. But now that I know stream[0:'\n'] won't work, I'll go
  15205. back to stream.readuntil( )
  15206.  
  15207.  
  15208. No effort has been made to optimize the reads or the copying
  15209. assignments, except some slight effort to avoid reading in the
  15210. whole file. ( And in one place I break that rule too - I was in
  15211. a hurry to finish and use it! ) 
  15212.  
  15213. But it's more fodder for discussion of Classes and Types in python.
  15214.  
  15215. It (mostly) works on posix.popen input pipes, but it doesn't yet
  15216. work exactly the way I want it to. That's 'cause it isn't yet
  15217. written to do what I want yet. ( I probably need to read with
  15218. a timeout, so that it will only read in what's available. I don't
  15219. know if I will pursure this - it's not necessary for me at the 
  15220. moment. ) So you will hang on len( pipestream ), for example, if
  15221. the output is not complete. I would like to process only up to
  15222. what is immediately available. 
  15223.  
  15224. But I *have* noticed an anomaly with how the read method handles EOF 
  15225. from the terminal: 
  15226.  
  15227. >>>sys.stdin.read( 2 )
  15228. \n
  15229. \n
  15230. returns => '\012\012' 
  15231.  
  15232. >>>sys.stdin.read(2)
  15233. ^D
  15234. returns immediately => '' 
  15235.  
  15236. >>>sys.stdin.read(2)
  15237. \n
  15238. ^D
  15239. \n
  15240. finally returns with => '\012\012' 
  15241.  
  15242.  
  15243. Maybe this is a 'feature' of gnu-readline ? 
  15244.  
  15245.  
  15246.  
  15247. And - while on the subject of 'read' - I was considering trying the new
  15248. array module if I make an attempt to optomize the istream module, and I
  15249. noticed that the read and write methods in the array module are
  15250. "backwards" compared to the other read methods: 
  15251.     array_obj.read( file_obj, count )
  15252.     vs.
  15253.     string = file_obj.read( nchars )
  15254.  
  15255. The reason this is so is clear. But maybe array_obj.read() should 
  15256. be array_obj.readfrom() ? ( Am I pursuing a foolish consistency here? )
  15257.  
  15258.  
  15259. -- Steve Majewski 
  15260.  
  15261.  
  15262. ----------
  15263. #!/usr/local/bin/python
  15264. #
  15265. import string
  15266.  
  15267. numeric_types = ( type(0), type(0L), type(0.0) )
  15268.  
  15269.  
  15270. class IStream:
  15271.     def __init__( self, source ):
  15272.         self.buffer = []
  15273.         self.indx = 0
  15274.         self.source = source
  15275.         self._bsize = 1024 
  15276.     def next( self ):
  15277.         if ( self.indx == len( self.buffer )) :
  15278.             self.buffer = self.source.read( self._bsize )
  15279.             self.indx = 0
  15280.         self.indx = self.indx + 1
  15281.         return self.buffer[self.indx-1:self.indx]
  15282.     def readuntil( self, delim ):
  15283.         temp = ''
  15284.         c = None
  15285.         while( '' <> c <> delim ):
  15286.             c = self.next()
  15287.             temp = temp + c 
  15288.         return temp
  15289.     def pushback( self, oldstring ):
  15290.         self.buffer = oldstring + self.buffer[self.indx:]
  15291.         self.indx = 0 
  15292.         return None 
  15293. # note: all of the "sequential" methods will "sequentialize" the stream -
  15294. # i.e. set start of buffer to indx, and possibly read in more ( or the
  15295. # entire stream ).
  15296.     def _normal_( self ):
  15297.         if  len(self.buffer) == 0  : 
  15298.             self.buffer = self.source.read( self._bsize )
  15299.             self.indx = 0 
  15300.         elif ( self.indx <> 0 ): 
  15301.             self.buffer = self.buffer[self.indx:] + self.source.read( self._bsize )
  15302.             self.indx = 0
  15303.     def _readall_( self ):
  15304.         self._normal_()
  15305.         tmp = self.source.read( self._bsize )
  15306.         while ( tmp <> '' ): 
  15307.             self.buffer = self.buffer + tmp 
  15308.             tmp = self.source.read( self._bsize ) 
  15309.     def __len__( self ):
  15310.         self._readall_()
  15311.         return len( self.buffer ) 
  15312.     def __getitem__( self, key ):
  15313.         self._normal_()
  15314.         if ( 0 <= key > len(self.buffer) ): 
  15315.             self.buffer = self.buffer + self.source.read( key - len(self.buffer) )
  15316.         else:
  15317.             self._readall_()
  15318.         return self.buffer[key]
  15319.     def _string_index_( self, k ):
  15320.         if  type(k) in numeric_types  : return k
  15321.         if  type(k) <> type('') :  raise IndexError
  15322.         i = string.find( self.buffer, k )
  15323.         if ( i < 0 ) : 
  15324.             self.__readall__()    # this should be incremental, not READALL.
  15325.             i = string.find( self.buffer )
  15326.             if i < 0 : raise IndexError
  15327.         return i
  15328.  
  15329.     def __getslice__( self, i, j ):
  15330.         self._normal_()
  15331.         limit = len( self.buffer )
  15332.         if  type(i) == type('') : i = self._string_index_( i )
  15333.         if  type(j) == type('') : j = self._string_index_( j )
  15334.         if ( i < 0 ) or ( j < 0 ):
  15335.             self._readall_()
  15336.         m = max( i, j )
  15337.         if m > limit: 
  15338.             m = m - limit 
  15339.             self.buffer = self.buffer + self.source.read( m ) 
  15340.         return self.buffer[i:j] 
  15341.  
  15342.  
  15343.  
  15344.     
  15345.  
  15346. def goodtest( filename ):
  15347.     S = IStream( open( filename, 'r' ) )
  15348.     print 'S[0]: ', S[0]    
  15349.     print 'S[0:10]: ', S[0:10]
  15350.     print 'for I in range( 1,20 ): S.next(): ' 
  15351.     for i in range( 1, 20 ):
  15352.         print S.next(),
  15353.     for i in range( 1, 3 ):
  15354.         print i,': S.readuntil(":")'
  15355.         print S.readuntil(':')
  15356.     x = S.readuntil( '\n' )
  15357.     print 'x = readuntil( newline ): '
  15358.     print x
  15359.     S.pushback( x[-3:] )
  15360.     print 'S.pushback( x[-3:] ); x = readuntil( newline ): '
  15361.     x = S.readuntil( '\n' )
  15362.     print x
  15363.     print 'S[0:120]: ', S[0:120]
  15364.     print 'S[-120:]: ', S[-120:]
  15365.     return S
  15366.  
  15367.  
  15368.  
  15369. def alltest( filename ):
  15370.     S = goodtest( filename )
  15371.     print '\n*This test will *FAIL*... '
  15372.     print 'S[0:\'n\']: ... '
  15373.     print S[0:'\n'] 
  15374.  
  15375. import sys
  15376. if ( len(sys.argv) > 1 ) : 
  15377.     for F in sys.argv[1:] :
  15378.         print ' Filename: ', F
  15379.         alltest( F ) 
  15380.  
  15381. 
  15382. 
  15383. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  15384.     id AA08821 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 09:22:34 +0200
  15385. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  15386.     id AA25711; Thu, 9 Sep 1993 03:21:38 -0400
  15387. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  15388.     id AA13910; Thu, 9 Sep 93 03:21:35 EDT
  15389. Received: by kaos.ksr.com (4.1/KSR-2.0)
  15390.     id AA11962; Thu, 9 Sep 93 03:21:31 EDT
  15391. Message-Id: <9309090721.AA11962@kaos.ksr.com>
  15392. To: sdm7g@Virginia.EDU, python-list@cwi.nl
  15393. Subject: Re: Thoughts and proposals about types and classes
  15394. Date: Thu, 09 Sep 93 03:21:31 -0400
  15395. From: Tim Peters <tim@ksr.com>
  15396.  
  15397. I agree the type system is sometimes clunky in practice, for the reasons
  15398. you give:  the distinctions among built-in types are sometimes too fine,
  15399. and among (at least conceptually -- is a new class really a new type?
  15400. hmm) user-defined types often too gross.
  15401.  
  15402. But I don't have a nice answer.  It's always been possible to worm around
  15403. the perceived clunkiness with what, by any objective measure, is very
  15404. simple code (albeit perhaps not _obvious_ code, at first; your isnumeric
  15405. function fits in here), and no Real Simple extension satisfies.
  15406.  
  15407. E.g., sometimes I want to know whether an object is specifically a plain
  15408. integer, sometimes any flavor of integer, sometimes any built-in numeric
  15409. type, and sometimes just whether the object supports something it _calls_
  15410. "subtraction" (the Dates module was interesting in this respect, since
  15411. it's both a real stretch to call a Date object a numeric type, and a real
  15412. convenience to define _some_ of the numeric operations on Date objects).
  15413.  
  15414. Quite some time ago, a certain well-known Python wizard favored me with a
  15415. lucid discussion of some of these issues in E-Mail; I'll reproduce part
  15416. of that here, without their permission:
  15417.  
  15418. > >[tim]
  15419. > >Ha!  You can justify
  15420. > >     if type(self) is type(other) and other.__class__ is Complex:
  15421. > >
  15422. > >but you can't call it "wonderfully clear" <grin>.  Supposing that "type"
  15423. > >returned a unique type for instances of user-defined classes, and that
  15424. > >class objects had a __type__ attribute which was the type of instances of
  15425. > >that class, _this_ would be wonderfully clear:
  15426. > >
  15427. > >     if type(other) is Complex.__type__:
  15428. > >
  15429. > >I'm not in love with that notation, I'm just trying to improve your
  15430. > >esthetic judgment <wink>.
  15431.  
  15432. > [a certain well-known python wizard]
  15433. > Yes, but this has the problem with derived classes explained above.
  15434. > Maybe I should do it anyway, and also add a simple way to test for
  15435. > derived classes.
  15436.  
  15437. > [and "the problem with derived classes explained above"]
  15438. > ...
  15439. > Seriously, even though it wouldn't be too hard to introduce a new type
  15440. > object for each class, I don't know if this would solve too many
  15441. > problems.  I can foresee one new problem:  derived classes.  Naive code
  15442. > implementing e.g. complex numbers that tests whether two objects have
  15443. > the same type will work until someone derives a trivial class...
  15444. >
  15445. > Languages like C++ sidestep this issue by not making classes and types
  15446. > first-class objects.  The compiler has a number of tests similar to my
  15447. > proposed sametype(), e.g. compatible_for_assignment(), etc.
  15448. >
  15449. > In Python most tests for type compatibility in the interpreter are
  15450. > done on a much more pragmatic basis:  the only requirement is that an
  15451. > object supports the operations that are actually applied to it.  This
  15452. > means that you can write "polymorphic" code, which doesn't care
  15453. > whether the argument to a function has exactly the right type, as long
  15454. > as it supports the proper operations or has the proper attributes.
  15455. > For example, it is now possible to substitute a user-defined object
  15456. > for sys.stdout; the only requirement of this object is that it has a
  15457. > method "write" taking a string argument.  In C++, this is impossible:
  15458. > a common base class must exist.
  15459. >
  15460. > It follows that explicit type checks in Python code should be
  15461. > exceptions to the rule, and indeed there is often something fishy
  15462. > whenever type() is called.  However, for __coerce__ functions as used
  15463. > in Complex or Rat there really isn't a serious alternative.  I suppose
  15464. > a cheap way of testing for a subclass would help a little.  This
  15465. > doesn't help in case someone creates a "Complex lookalike" but that
  15466. > doesn't sound like a big problem in practice (and at least one of the
  15467. > types could be taught about the other).
  15468.  
  15469. I've since taken the "the only requirement is that an object supports the
  15470. operations that are actually applied to it" as a useful design principle,
  15471. and found that most of my uses of "type" vanished as a result, and that
  15472. the code became more general even while becoming simpler.
  15473.  
  15474. A neat example of the latter phenomenon is a rework of the Complex
  15475. module:  by pruning out overly-protective uses of "type", I got a Complex
  15476. module that works fine for Complex numbers whose real & imaginary parts
  15477. are arbitrary-precision rationals (or integers, or-- indeed --are Complex
  15478. themselves:  any objects that "support the operations applied to them").
  15479. This is slick!  "type" is really needed in only a few places, and half of
  15480. those just to worm around the non-coercion of + and * arguments.
  15481.  
  15482. So I pretty much stopped worrying about the type system.  However, since
  15483. I'm the primary consumer of the classes I write, I'm happy with obscure
  15484. error msgs from deep in the bowels of the class implementation; another
  15485. user would doubtless much rather be told up front "you can't divide a
  15486. complex by a dictionary" at the top level, and supplying that
  15487. friendliness would put me right back in the "type" business.  Messy
  15488. issues!
  15489.  
  15490. > [steve]
  15491. > Which leads me to comment on the 2nd half ... One result of the
  15492. > experiment was discovering that my attempt at a "string index" for a
  15493. > sequence didn't work : the index can only be an int!
  15494.  
  15495. There are similar (undocumented but certainly not crazy) constraints on
  15496. numeric operations.  E.g.,
  15497.  
  15498. >>> from Rat import rat
  15499. >>> r=rat(2,3)
  15500. >>> r/[5]
  15501. Stack backtrace (innermost last):
  15502.   File "<stdin>", line 1
  15503. TypeError: number coercion failed
  15504. >>> [5]/r
  15505. Stack backtrace (innermost last):
  15506.   File "<stdin>", line 1
  15507. TypeError: bad operand type(s) for /
  15508. >>>
  15509.  
  15510. Presumably I could trick the first one into working (whatever that might
  15511. mean in this context <grin>), but not the latter.  I agree it would be a
  15512. bit nicer if Python didn't constrain the kinds of objects passed to
  15513. __div__, __getslice__, etc.  You can _usually_ worm around these
  15514. restrictions by disguising the built-in object in a class instance, but I
  15515. see that doesn't work for __getslice__.
  15516.  
  15517. On the other hand, __getslice__(s,i,j) is documented as adding len(s) to
  15518. j if j<0 etc, so there appears to be a good reason for insisting that i &
  15519. j be ints (i.e., so that "j<0" and "j+len(s)" make sense!).
  15520.  
  15521. tickled-by-what-you-_wanted_-to-do-with-__getslice__-all-the-same-ly
  15522.    y'rs  - tim
  15523.  
  15524. Tim Peters   tim@ksr.com
  15525. not speaking for Kendall Square Research Corp
  15526. 
  15527. 
  15528. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  15529.     id AA28564 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 18:25:45 +0200
  15530. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa01482;
  15531.           9 Sep 93 12:25 EDT
  15532. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  15533.     id AA22936; Thu, 9 Sep 1993 12:25:06 -0400
  15534. Date: Thu, 9 Sep 1993 12:25:06 -0400
  15535. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  15536. Message-Id: <199309091625.AA22936@elvis.med.Virginia.EDU>
  15537. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  15538. To: Tim Peters <tim@ksr.com>, sdm7g@virginia.edu, python-list@cwi.nl
  15539. Subject: Re: Thoughts and proposals about types and classes
  15540.  
  15541. On Sep 9,  3:21, Tim Peters wrote:
  15542. > I've since taken the "the only requirement is that an object supports the
  15543. > operations that are actually applied to it" as a useful design principle,
  15544. > and found that most of my uses of "type" vanished as a result, and that
  15545. > the code became more general even while becoming simpler.
  15546. > A neat example of the latter phenomenon is a rework of the Complex
  15547. > module:  by pruning out overly-protective uses of "type", I got a Complex
  15548. > module that works fine for Complex numbers whose real & imaginary parts
  15549. > are arbitrary-precision rationals (or integers, or-- indeed --are Complex
  15550. > themselves:  any objects that "support the operations applied to them").
  15551. > This is slick!  "type" is really needed in only a few places, and half of
  15552. > those just to worm around the non-coercion of + and * arguments.
  15553. > So I pretty much stopped worrying about the type system.  However, since
  15554. > I'm the primary consumer of the classes I write, I'm happy with obscure
  15555. > error msgs from deep in the bowels of the class implementation; another
  15556. > user would doubtless much rather be told up front "you can't divide a
  15557. > complex by a dictionary" at the top level, and supplying that
  15558. > friendliness would put me right back in the "type" business.  Messy
  15559. > issues!
  15560.  
  15561. You're probably right! Doing some upfront error checking on the args
  15562. to give a coherent error message was actually the primary use I had 
  15563. in mind for a better type/class/subclass test. And even there, I can
  15564. always wrap the whole thing with a "try: ... ; except TypeError: " 
  15565. to give *MY* error message, rather than the one from "deep in the
  15566. bowels". But, as in Guido's previous remarks contra-non-qualified-excepts 
  15567. ( Try: ; Except: #(everything) ), in those few cases when I actually
  15568. KNOW exactly what I want, I would like to be exactly specific, and not
  15569. worry that I might catch an exception that is not from the expected 
  15570. cause. Also, the info from an exception might not be specific enough 
  15571. ( like WHICH arg was bad? ) unless you first test some guarded
  15572. commands:
  15573.     for ARG in ARGLIST:
  15574.     try:    tmp = ARG + 0 # or perhaps tmp = ARG[0] for sequences
  15575.     except: raise some_more_specific_error
  15576.         
  15577.  
  15578. I've got code where I DO check for type(()) or type([]). 
  15579. And I would prefer, for just the reasons you state, to not be
  15580. *overly* restrictive: I probably really mean to test for is_a_mutable_
  15581. sequence? , not <type 'list'>. So I'm looking for an easy way to
  15582. do this. 
  15583.  
  15584. def issequence( s ):
  15585.     if type(s) in ( type(()), type([]) ):  return 1
  15586.     if type(s) <> TypeInstance : return 1
  15587.     for X in ( '__len__', '__getitem__', '__getslice__' ):
  15588.         if not hasattr( s, X ) : return 0 
  15589.     return 1 
  15590.  
  15591. is not too bad, but the list gets longer for mutable sequences and
  15592. numerics. I don't think the convention of having to implement 
  15593. __isnumeric__ or __issequence__ would be too much to ask to 
  15594. make the implementation of issequence() of isnumeric() easier 
  15595. and more effecient. And it would also be a promise of some 
  15596. "reasonable" semantics. ( and like all promises, you should consider
  15597. the promiser! ) 
  15598.  
  15599. [ That was my minimal & initial proposal - the other ramblings were
  15600.  an effort to see if there was something more general that could 
  15601.  be done with the type/class system. ]
  15602.  
  15603. Your comments about _you_ being the primary consumer of your classes 
  15604. is on the mark. Most of my use of python is when I want a quick 
  15605. ( and possibly dirty ) solution, and I don't really want to bother
  15606. coding argument checks and error messages. In those cases, python's
  15607. default behaviour is quite sufficient. But if python actively 
  15608. discourages error checking by making it awkward or difficult or 
  15609. time consuming, then it's use for more ambitious "end user" programs 
  15610. may be limited. 
  15611.  
  15612. [ This brings us back to the "What are YOU using python for" thread. 
  15613.   More entries are hereby solicited! ] 
  15614.  
  15615.  
  15616. > > [steve]
  15617. > > Which leads me to comment on the 2nd half ... One result of the
  15618. > > experiment was discovering that my attempt at a "string index" for a
  15619. > > sequence didn't work : the index can only be an int!
  15620.  [ ... ]
  15621. > tickled-by-what-you-_wanted_-to-do-with-__getslice__-all-the-same-ly
  15622. >    y'rs  - tim
  15623.  
  15624. I can see reasons why it *SHOULDN'T* work - both technical/implementation 
  15625. reasons AND semantic/reasonable-expectation reasons. I was just playing
  15626. around and was trying to see what I could and couldn't do. I don't want
  15627. it to be interpreted as a request or complaint that it didn't work. 
  15628. Especially in the light of my pedantic (actual) complaint that 
  15629. array.read( file, count ) OUGHT to be array.readfrom( file, count ) 
  15630. since there should be a reasonable expectation that obj.read() is a 
  15631. method of something that can be "read" and takes an argument of "how
  15632. much" . ( Or, at least, there *WAS* a reasonable expectation until array
  15633. objects were added to the language. The counter point-of-view is than no
  15634. methods except those starting with "__" should be considered "sacred".)
  15635.  
  15636. I don't think 'seq[int]' is an unreasonable restriction. 
  15637.  
  15638.  
  15639. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  15640. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  15641. 
  15642. 
  15643. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  15644.     id AA00419 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 19:04:03 +0200
  15645. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  15646.     id AA14135; Thu, 9 Sep 93 10:04:54 -0700
  15647. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  15648.     id AA12084; Thu, 9 Sep 93 10:08:28 -0700
  15649. Received: by ushqgw.sequent.com with Microsoft Mail
  15650.     id <2C8F6208@ushqgw.sequent.com>; Thu, 09 Sep 93 10:04:08 PDT
  15651. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  15652. To: python-list <python-list@cwi.nl>,
  15653.         "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>,
  15654.         sdm7g <sdm7g@virginia.edu>, Tim Peters <tim@ksr.com>
  15655. Subject: Re: Thoughts and proposals about types and classes
  15656. Date: Thu, 09 Sep 93 10:02:00 PDT
  15657. Message-Id: <2C8F6208@ushqgw.sequent.com>
  15658. Encoding: 12 TEXT
  15659. X-Mailer: Microsoft Mail V3.0
  15660.  
  15661.  
  15662.  
  15663. Error checking (type checking) in code that retrieves information from 
  15664. outside a program seems perfectly valid (user or file input). Type checking 
  15665. to catch programming errors seems counter productive, especially if the 
  15666. error messages are going to be meaningless to the end-user (here the 
  15667. end-user is *not* the programmer). Python does a reasonably job to track 
  15668. down programming errors (the stack trace).
  15669.  
  15670. $0.02
  15671.  
  15672.      -Jaap-
  15673. 
  15674. 
  15675. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  15676.     id AA02225 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 19:50:55 +0200
  15677. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa20595;
  15678.           9 Sep 93 13:50 EDT
  15679. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  15680.     id AA21163; Thu, 9 Sep 1993 13:49:19 -0400
  15681. Date: Thu, 9 Sep 1993 13:49:19 -0400
  15682. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  15683. Message-Id: <199309091749.AA21163@elvis.med.Virginia.EDU>
  15684. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  15685. To: "Jaap Vermeulen (jaap)" <jaap@sequent.com>,
  15686.         python-list <python-list@cwi.nl>, sdm7g <sdm7g@virginia.edu>,
  15687.         Tim Peters <tim@ksr.com>
  15688. Subject: Re: Thoughts and proposals about types and classes
  15689.  
  15690. On Sep 9, 10:02, "Jaap Vermeulen (jaap)" wrote:
  15691. > Error checking (type checking) in code that retrieves information from 
  15692. > outside a program seems perfectly valid (user or file input). Type checking 
  15693. > to catch programming errors seems counter productive, especially if the 
  15694. > error messages are going to be meaningless to the end-user (here the 
  15695. > end-user is *not* the programmer). Python does a reasonably job to track 
  15696. > down programming errors (the stack trace).
  15697. > $0.02
  15698. >      -Jaap-
  15699.  
  15700.  
  15701. But a Class is just *supposed* to be THAT TYPE of interface. 
  15702. A class method get's it's arguments ( except for "self" ) 
  15703. from "outside". So there are TWO types of error messages:
  15704.  
  15705. "Something unexpected happened - This class is broken!" 
  15706.   - stack trace and other interesting stuff for the implementor
  15707.     (or re-implementor or maintainer) of that class.
  15708.  
  15709.   [for the Class programmer]
  15710.  
  15711. -OR-
  15712.  
  15713. "You are giving me garbage! - please read the instructions on
  15714.   how to use this class and/or method."  
  15715.  
  15716.   [for the Class end-user] 
  15717.  
  15718.  
  15719.  
  15720. That's largely what OO-design/programming is all about: (isn't it?)
  15721. The distinction of inside/outside on many different levels;
  15722. black boxes, interfaces, etc. The programmer IS the end 
  15723. user - of a Class. 
  15724.  
  15725.  
  15726.  
  15727. [ <unrelated-digression-about-error-handlers>:
  15728.  One of the things I used to like about VAX/VMS exceptions was
  15729.  that they also had levels of severity: (Info,Warning,Error,Severe )
  15730.  and you could raise/catch/ignore signals of a specific level. 
  15731.  So instead of using a debug or verbose flag, you would just 
  15732.  lower the severity level to catch and report warnings. But the
  15733.  exception handler had a different model than python - after 
  15734.  catching a exception signal, you could examine it, and return
  15735.  to the site of the exception - which is exactly what you would
  15736.  want to do for warnings and informational messages. Or re-raise
  15737.  the exception for more uplevel processing. ] 
  15738.  
  15739. - Steve M.
  15740.  
  15741.  
  15742. BTW: there are a few bugs in my IStream Class. It passed 
  15743. the tests OK on small files, but accessing stream[indx] 
  15744. before the buffer is loaded by some other access seems
  15745. to make it try to read in the whole file ( which is 
  15746. quite noticable when you try it on a LARGE file. ) 
  15747.  
  15748. Well - I *did* note that it was not_ready_for_prime_time !
  15749. I'll post a better version when it's finished ( along with
  15750. the readuntil( 'string' ) or readuntil( regexp ) additions.
  15751. Please excuse me for posting alpha code - I just want to
  15752. keep the discussion moving with some examples. 
  15753.  
  15754. 
  15755. 
  15756. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  15757.     id AA03246 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 20:19:58 +0200
  15758. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  15759.     id AA17558; Thu, 9 Sep 93 11:20:52 -0700
  15760. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  15761.     id AA14470; Thu, 9 Sep 93 11:23:13 -0700
  15762. Received: by ushqgw.sequent.com with Microsoft Mail
  15763.     id <2C8F738D@ushqgw.sequent.com>; Thu, 09 Sep 93 11:18:53 PDT
  15764. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  15765. To: python-list <python-list@cwi.nl>,
  15766.         "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>,
  15767.         sdm7g <sdm7g@virginia.edu>, Tim Peters <tim@ksr.com>
  15768. Subject: Re: Thoughts and proposals about types and classes
  15769. Date: Thu, 09 Sep 93 11:09:00 PDT
  15770. Message-Id: <2C8F738D@ushqgw.sequent.com>
  15771. Encoding: 15 TEXT
  15772. X-Mailer: Microsoft Mail V3.0
  15773.  
  15774.  
  15775.  
  15776. | But a Class is just *supposed* to be THAT TYPE of interface.
  15777.  
  15778. I tend to disagree. I think the end-user of an application will not care 
  15779. about the internal structure of the application and/or the techniques used 
  15780. to create it.
  15781.  
  15782. | "You are giving me garbage! - please read the instructions on
  15783. |   how to use this class and/or method."
  15784.  
  15785. I can sympathize with the reasoning. I guess I would add rigid checking as a 
  15786. debugging tool during development of an application.
  15787.  
  15788.      -Jaap-
  15789. 
  15790. 
  15791. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  15792.     id AA04108 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 20:41:34 +0200
  15793. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa00946;
  15794.           9 Sep 93 14:41 EDT
  15795. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  15796.     id AA22873; Thu, 9 Sep 1993 14:41:05 -0400
  15797. Date: Thu, 9 Sep 1993 14:41:05 -0400
  15798. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  15799. Message-Id: <199309091841.AA22873@elvis.med.Virginia.EDU>
  15800. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  15801. To: python-list@cwi.nl
  15802. Subject: istream class bugs
  15803.  
  15804. As I noted - I found that my IStream class was reading in the
  15805. entire in some cases. 
  15806.  
  15807. There was a bug which caused it to read the entire class when 
  15808. __getitem__ was the first method used ( and the buffer was 
  15809. therefore initially empty ). That was the easy part to fix.
  15810.  
  15811. But there is also a problem with __getslice__ - it appears to 
  15812. ALWAYS read in the whole file. This appears to be a side effect
  15813. of the fact that getslice normalizes negative indexes by subtracting
  15814. the length. ( I point I hadn't noted at first! ) and it appears 
  15815. that it always calls __len__(), even when the indexes are positive. 
  15816. ( maybe it is also checking if they are in-bounds ? ) 
  15817.  
  15818. Well - that sort of makes that a useless method for the uses I had
  15819. been considering. Maybe I should go back to the earlier version 
  15820. without the pseudo sequence operation tacked on. The indexing and
  15821. slicing was really only needed as a sort of 'peek' into the stream. 
  15822. I can just as well add a peek( n ) method or use the pushback()
  15823. method to do the same thing. 
  15824.  
  15825. -- Steve M.
  15826.  
  15827. 
  15828. 
  15829. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  15830.     id AA04816 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 21:00:20 +0200
  15831. To: python-list@cwi.nl
  15832. Subject: JPEG module
  15833. X-Organization: Mark V Systems Ltd.
  15834. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  15835. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  15836. Date: Thu, 9 Sep 93 11:59:44 PDT
  15837. From: lance@markv.com
  15838. Sender: lance@markv.com
  15839. Message-Id:  <9309091159.aa03132@hermix.markv.com>
  15840. Source-Info:  From (or Sender) name not authenticated.
  15841.  
  15842.  
  15843. Does anyone have the libraries to allow the JPEG module to be used?
  15844. Where can I grab it from?
  15845. Does anyone have the same type of module for GIF files?
  15846.  
  15847. Thank you,
  15848.  
  15849. --
  15850.  
  15851. Lance Ellinghouse           lance@markv.com
  15852.  
  15853. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  15854. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  15855. You can recieve my Public Key by `finger lance@mark.com`
  15856. 
  15857. 
  15858. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  15859.     id AA06657 (5.65b/3.10/CWI-Amsterdam); Thu, 9 Sep 1993 21:51:23 +0200
  15860. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa14819;
  15861.           9 Sep 93 15:51 EDT
  15862. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  15863.     id AA20712; Thu, 9 Sep 1993 15:50:43 -0400
  15864. Date: Thu, 9 Sep 1993 15:50:43 -0400
  15865. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  15866. Message-Id: <199309091950.AA20712@elvis.med.Virginia.EDU>
  15867. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  15868. To: "Jaap Vermeulen (jaap)" <jaap@sequent.com>,
  15869.         python-list <python-list@cwi.nl>, sdm7g <sdm7g@virginia.edu>,
  15870.         Tim Peters <tim@ksr.com>
  15871. Subject: Re: Thoughts and proposals about types and classes
  15872.  
  15873.  
  15874.  
  15875. steve> But a Class is just *supposed* to be THAT TYPE of interface.
  15876.  
  15877. jaap> I tend to disagree. I think the end-user of an application will not 
  15878. jaap> care about the internal structure of the application and/or the 
  15879. jaap> techniques used to create it.
  15880.  
  15881. I agree with that sentence - but it's beside the point. The point I
  15882. was trying to make was: 
  15883.  
  15884.  I think the end-user of an CLASS will not care about the internal
  15885.  structure of the CLASS and/or the techniques used to create it.
  15886.  
  15887.  
  15888. steve> "You are giving me garbage! - please read the instructions on
  15889. steve>   how to use this class and/or method."
  15890.  
  15891. jaap> I can sympathize with the reasoning. I guess I would add rigid
  15892. jaap> checking as a debugging tool during development of an application.
  15893.  
  15894. Again - the distinction I was trying to make:
  15895.  
  15896.  Type checking and some error checking that was put there to check
  15897.  that the class actually works as it is supposed to, is a debugging
  15898.  tool that can be removed when it has served it's purpose. Which is
  15899.  to show that given the proper input, the class is consistent and 
  15900.  correct in it's behaviour. 
  15901.  
  15902.  Assuming for the moment that the class is bug free and consistent, it
  15903.  should still give a reasonable error message when it is misused or
  15904.  given the wrong input arguments. 
  15905.  
  15906. To move the interface lines for a moment - what you are saying is
  15907. rather like: 
  15908.  "The program is bug free, so there is no need for error messages - 
  15909.  if the users give it the wrong input, it will crash and the OS 
  15910.  will tell them it crashed. They can then check their input files
  15911.  and see what THEY did wrong. And even if there IS a bug, they 
  15912.  wouln't be interested in the details!" 
  15913.  
  15914. No - the end user is not interested in the details of the program's
  15915. implementation. But they are interested in the distinction between:
  15916. 'no such file', 'no privilege to read file', and 'input file incorrect
  15917. format'. 
  15918.  
  15919.  
  15920.  
  15921. A related question is whether the default error messages are 
  15922. sufficient. In many cases, the error message from 'deep in the 
  15923. bowels' IS going to be the correct one. If it is a TypeError 
  15924. when your try to actually USE the argument, then it was probably
  15925. going to be a TypeError raised if and when you checked it. 
  15926.  
  15927. When I moved to unix from VMS, I had to adjust my programming 
  15928. style somewhat. I had grown accustomed to the fact the VMS 
  15929. default system error messages and behaviour were usually sufficient 
  15930. that the program didn't need to do as much. The same programs
  15931. moved to unix gave incomprehensible messages ( or none at all ) 
  15932. And, in fact, the only problem with VMS messages was that they
  15933. often gave you all of the stack trace and other stuff not needed
  15934. by the end user. So the usual reason for adding explicit error 
  15935. checking was to REMOVE information that was a distraction to the
  15936. end-user. 'No such filename' does NOT need a stack trace. 
  15937.  
  15938. Specifically - python's default error behaviour is not bad -
  15939. the typical reason to change it is the same as in VMS - too 
  15940. MUCH information. 
  15941.  
  15942. In general, I'm saying that there is a distinction to be made
  15943. between implementor-oriented error messages ( This program/
  15944. procedure/class/shell-script/whatever has a BUG ) and end-user
  15945. oriented error messages ( You are feeding me the wrong imput. ) 
  15946. But in the case of reusable classes, another programmer 
  15947. ( or even the same programmer 6 months later ) is the "end-user"
  15948. of the class. The same inside/outside distinction is valid at
  15949. several levels of the hierarchy. 
  15950.  
  15951. Rule: "You shouldn't have to open up a black box and take it 
  15952. apart to find out you've been pushing the wrong buttons!" 
  15953.  
  15954. Corollary: "Every black box should have at least TWO blinking
  15955. lights: "Paper Jam" and "Service Required" ( or equivalent )"
  15956.  
  15957.  
  15958. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  15959. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  15960. 
  15961. 
  15962. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  15963.     id AA12934 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 00:17:05 +0200
  15964. From: Lance Ellinghouse <lance@markv.com>
  15965. X-Mailer: SCO System V Mail (version 3.2)
  15966. To: python-list@cwi.nl
  15967. Subject: diffs to compile under SCO ODT 2.0
  15968. Date: Thu, 9 Sep 93 15:15:52 PDT
  15969. Message-Id:  <9309091516.aa21796@hermix.markv.com>
  15970.  
  15971. Here is a set of diffs for the following files that will allow
  15972. PYTHON 0.9.9 to compile under SCO ODT 2.0. I have not included the
  15973. Makefile diffs but can make them available if someone wants them..
  15974. The diffs are for the following files:
  15975.     ceval.c, posixmodule.c, socketmodule.c, timemodule.c
  15976.  
  15977. I hope these can get put into the distribution...
  15978.  
  15979. Thank you,
  15980. Lance Ellinghouse
  15981. lance@markv.com
  15982. ===================================================================
  15983. RCS file: /u/lance/CVS/python/src/ceval.c,v
  15984. retrieving revision 1.1.1.1
  15985. diff -c -r1.1.1.1 ceval.c
  15986. *** 1.1.1.1    1993/09/09 20:57:38
  15987. --- ceval.c    1993/09/09 22:02:40
  15988. ***************
  15989. *** 92,98 ****
  15990.   static void fast_2_locals PROTO((frameobject *));
  15991.   static int access_statement PROTO((object *, object *, frameobject *));
  15992.   
  15993.   /* Pointer to current frame, used to link new frames to */
  15994.   
  15995.   static frameobject *current_frame;
  15996. --- 92,97 ----
  15997. ***************
  15998. *** 1652,1658 ****
  15999.       err_setval(error_type, error_value);
  16000.   }
  16001.   
  16002. ! static void
  16003.   mergelocals()
  16004.   {
  16005.       locals_2_fast(current_frame, 1);
  16006. --- 1651,1657 ----
  16007.       err_setval(error_type, error_value);
  16008.   }
  16009.   
  16010. ! void
  16011.   mergelocals()
  16012.   {
  16013.       locals_2_fast(current_frame, 1);
  16014. ===================================================================
  16015. RCS file: /u/lance/CVS/python/src/posixmodule.c,v
  16016. retrieving revision 1.1.1.1
  16017. diff -c -r1.1.1.1 posixmodule.c
  16018. *** 1.1.1.1    1993/09/09 20:57:35
  16019. --- posixmodule.c    1993/09/09 22:05:16
  16020. ***************
  16021. *** 35,41 ****
  16022.   #include <dos.h>
  16023.   #endif
  16024.   
  16025. ! #ifdef __sgi
  16026.   #define DO_PG
  16027.   #endif
  16028.   
  16029. --- 35,41 ----
  16030.   #include <dos.h>
  16031.   #endif
  16032.   
  16033. ! #if defined(__sgi) || defined(M_UNIX)
  16034.   #define DO_PG
  16035.   #endif
  16036.   
  16037. ===================================================================
  16038. RCS file: /u/lance/CVS/python/src/socketmodule.c,v
  16039. retrieving revision 1.1.1.1
  16040. diff -c -r1.1.1.1 socketmodule.c
  16041. *** 1.1.1.1    1993/09/09 20:57:35
  16042. --- socketmodule.c    1993/09/09 22:05:46
  16043. ***************
  16044. *** 78,84 ****
  16045. --- 78,86 ----
  16046.   #include <signal.h>
  16047.   #include <sys/socket.h>
  16048.   #include <netinet/in.h>
  16049. + #ifndef M_UNIX
  16050.   #include <sys/un.h>
  16051. + #endif
  16052.   #include <netdb.h>
  16053.   
  16054.   #ifdef i860
  16055. ***************
  16056. *** 233,243 ****
  16057. --- 235,247 ----
  16058.           return ret;
  16059.       }
  16060.   
  16061. + #ifndef M_UNIX
  16062.       case AF_UNIX:
  16063.       {
  16064.           struct sockaddr_un *a = (struct sockaddr_un *) addr;
  16065.           return newstringobject(a->sun_path);
  16066.       }
  16067. + #endif
  16068.   
  16069.       /* More cases here... */
  16070.   
  16071. ***************
  16072. *** 263,268 ****
  16073. --- 267,273 ----
  16074.   {
  16075.       switch (s->sock_family) {
  16076.   
  16077. + #ifndef M_UNIX
  16078.       case AF_UNIX:
  16079.       {
  16080.           static struct sockaddr_un addr;
  16081. ***************
  16082. *** 280,285 ****
  16083. --- 285,291 ----
  16084.           *len_ret = len + sizeof addr.sun_family;
  16085.           return 1;
  16086.       }
  16087. + #endif
  16088.   
  16089.       case AF_INET:
  16090.       {
  16091. ***************
  16092. *** 318,328 ****
  16093. --- 324,336 ----
  16094.   {
  16095.       switch (s->sock_family) {
  16096.   
  16097. + #ifndef M_UNIX
  16098.       case AF_UNIX:
  16099.       {
  16100.           *len_ret = sizeof (struct sockaddr_un);
  16101.           return 1;
  16102.       }
  16103. + #endif
  16104.   
  16105.       case AF_INET:
  16106.       {
  16107. ***************
  16108. *** 1060,1066 ****
  16109. --- 1068,1076 ----
  16110.       if (SocketError == NULL || dictinsert(d, "error", SocketError) != 0)
  16111.           fatal("can't define socket.error");
  16112.       insint(d, "AF_INET", AF_INET);
  16113. + #ifndef M_UNIX
  16114.       insint(d, "AF_UNIX", AF_UNIX);
  16115. + #endif
  16116.       insint(d, "SOCK_STREAM", SOCK_STREAM);
  16117.       insint(d, "SOCK_DGRAM", SOCK_DGRAM);
  16118.       insint(d, "SOCK_RAW", SOCK_RAW);
  16119. ===================================================================
  16120. RCS file: /u/lance/CVS/python/src/timemodule.c,v
  16121. retrieving revision 1.1.1.1
  16122. diff -c -r1.1.1.1 timemodule.c
  16123. *** 1.1.1.1    1993/09/09 20:58:47
  16124. --- timemodule.c    1993/09/09 22:06:02
  16125. ***************
  16126. *** 38,43 ****
  16127. --- 38,47 ----
  16128.   #include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
  16129.   #endif
  16130.   
  16131. + #ifdef M_UNIX
  16132. + #define HAVE_GETTIMEOFDAY
  16133. + #endif
  16134.   #ifdef macintosh
  16135.   #define NO_UNISTD
  16136.   #endif
  16137. ***************
  16138. *** 70,75 ****
  16139. --- 74,87 ----
  16140.   #else /* !unix */
  16141.   #include <time.h>
  16142.   #endif /* !unix */
  16143. + #ifdef M_UNIX
  16144. + #include <time.h>
  16145. + #define _timezone    timezone
  16146. + #define _altzone    altzone
  16147. + #define _daylight    daylight
  16148. + #define _tzname        tzname
  16149. + #endif
  16150.   
  16151.   #ifdef SYSV
  16152.   /* Access timezone stuff */
  16153. 
  16154. 
  16155. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  16156.     id AA00616 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 05:41:17 +0200
  16157. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id ab00891;
  16158.           9 Sep 93 23:41 EDT
  16159. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  16160.     id AA14343; Thu, 9 Sep 1993 23:40:59 -0400
  16161. Date: Thu, 9 Sep 1993 23:40:59 -0400
  16162. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  16163. Message-Id: <199309100340.AA14343@elvis.med.Virginia.EDU>
  16164. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  16165. To: python-list@cwi.nl
  16166. Subject: Obfuscated Python Contest Entry
  16167.  
  16168. #!/usr/local/bin/python
  16169. #
  16170. # Obfuscated Python Contest Entry
  16171. #  -or- 
  16172. # How to make your python look more like C.
  16173. #
  16174. # submitted without comment by:
  16175. #  Steve Majewski <sdm7g@Virginia.EDU>
  16176. #
  16177.  
  16178. from sys import stdin,stdout
  16179.  
  16180. The_End = '_An_Expected_End_of_Input_'
  16181.  
  16182. def err(s):
  16183.     raise s
  16184.  
  16185. def getline():
  16186.     return( stdin.readline() or err(The_End) )
  16187.  
  16188. def echo():
  16189.    try:
  16190.         while( stdout.write(getline()) or 1 ) : pass
  16191.    except The_End:
  16192.     print The_End
  16193.  
  16194. echo()
  16195.  
  16196. 
  16197. 
  16198. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  16199.     id AA01622 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 06:24:48 +0200
  16200. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  16201.     id AA12305; Fri, 10 Sep 1993 00:22:10 -0400
  16202. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  16203.     id AA29996; Fri, 10 Sep 93 00:22:05 EDT
  16204. Received: by kaos.ksr.com (4.1/KSR-2.0)
  16205.     id AA10199; Fri, 10 Sep 93 00:22:02 EDT
  16206. Message-Id: <9309100422.AA10199@kaos.ksr.com>
  16207. To: sdm7g@virginia.edu, python-list@cwi.nl
  16208. Subject: Re: Thoughts and proposals about types and classes
  16209. Date: Fri, 10 Sep 93 00:22:01 -0400
  16210. From: Tim Peters <tim@ksr.com>
  16211.  
  16212. There's a footnote in the reference manual, to the effect that Python
  16213. "should" distinguish among classes implementing sequences, mappings, and
  16214. numerics.  There it's in the context of explaining the strange coercion
  16215. behavior for __add__ and __mul__ methods, but you're surely right that it
  16216. could have broader use.  The presence or absence of an __isnumeric__/
  16217. __issequence__/__ismapping__ attribute seems a decent way to make this
  16218. distinction.
  16219.  
  16220. I'm not sure what _meaning_ to ascribe to these predicates, though!
  16221. E.g., you've found it convenient to define a sequence type (the buffered
  16222. input class) that doesn't want to implement __getslice__ (for efficiency
  16223. reasons), and I've found it convenient to define a numeric type (the Date
  16224. class) that doesn't want to implement _most_ of the "numeric" operations.
  16225.  
  16226. Similarly, I suspect we both implement one-shot (throwaway, whatever)
  16227. sequence/mapping/numeric classes, purely for short-term syntactic
  16228. convenience, that don't implement most of the sequence/mapping/numeric
  16229. special methods.  And, e.g., I suspect that nobody yet has implemented a
  16230. new numeric type that supports the __lshift__ method -- not that it can't
  16231. be useful to do so, but that it's bound to be useful only rarely for a
  16232. new numeric type (what could it mean to shift a complex number? etc).
  16233.  
  16234. So I worry that if isnumeric(thing), issequence(thing) (etc) are added to
  16235. the language, we'll still be left wondering "OK, isequence(thing)/
  16236. isnumeric(thing)/whatever was true, but what _operations_ does this thing
  16237. support?".
  16238.  
  16239. If the answer is "it's up to the user to define-- and stick to --their
  16240. own conventions on this", there's little reason to build it into the
  16241. language, since the same effect can be easily-enough achieved "by hand",
  16242. by building the knowledge into a common module.  But if Python defines--
  16243. and enforces --some convention, we'll find it overly restrictive unless
  16244. it's too weak to solve the problem.
  16245.  
  16246.  
  16247. About using try/except to catch the kinds of errors in question, fully
  16248. agreed it's a bad approach.  When implementing new types that are
  16249. misused, the "in the bowels" exceptions are as often attribute errors as
  16250. type errors.  Sticking both kinds of exceptions on an enclosing "try" is
  16251. just begging for trouble.
  16252.  
  16253.  
  16254. > But if python actively discourages error checking by making it awkward
  16255. > or difficult or time consuming, then its use for more ambitious "end
  16256. > user" programs may be limited.
  16257.  
  16258. Well, even now it's less awkward in Python than in, e.g., COBOL, BASIC, C
  16259. or Fortran, but the latter get used anyway for far too many end user
  16260. programs that are far too ambitious <grin>.
  16261.  
  16262. I'm not convinced Python _can_ supply a solution to this, but it would
  16263. help if building one's own solution were a little cleaner.  E.g., a short
  16264. way to spell "type(THING) is type(a_class_instance) and THING.__class__
  16265. is CLASS" (or "... and (THING.__class__ is CLASS or CLASS in
  16266. THING.__class__.__bases__") would save a fair amount of discouraging
  16267. tedium.
  16268.  
  16269. > ...
  16270. > Especially in the light of my pedantic (actual) complaint that
  16271. > array.read( file, count ) OUGHT to be array.readfrom( file, count )
  16272. > since there should be a reasonable expectation that obj.read() is a
  16273. > method of something that can be "read" and takes an argument of "how
  16274. > much".
  16275.  
  16276. Your objection made good sense to me!
  16277.  
  16278. > ...
  16279. > I don't think 'seq[int]' is an unreasonable restriction.
  16280.  
  16281. But I do <grin>.  Note that, unlike __getslice__, __getitem__ can get
  16282. passed absolutely anything (ints, regexps, modules, lists, functions,
  16283. files, ...).  I have code that depends on that <wink>.
  16284.  
  16285. and-my-own-code-is-the-measure-of-all-things-ly y'rs  - tim
  16286.  
  16287. Tim Peters   tim@ksr.com
  16288. not speaking for Kendall Square Research Corp
  16289. 
  16290. 
  16291. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  16292.     id AA01762 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 06:31:06 +0200
  16293. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  16294.     id AA12321; Fri, 10 Sep 1993 00:28:20 -0400
  16295. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  16296.     id AA00114; Fri, 10 Sep 93 00:28:16 EDT
  16297. Received: by kaos.ksr.com (4.1/KSR-2.0)
  16298.     id AA10338; Fri, 10 Sep 93 00:28:13 EDT
  16299. Message-Id: <9309100428.AA10338@kaos.ksr.com>
  16300. To: sdm7g@virginia.edu
  16301. Subject: Re: Obfuscated Python Contest Entry
  16302. Cc: python-list@cwi.nl
  16303. Date: Fri, 10 Sep 93 00:28:12 -0400
  16304. From: Tim Peters <tim@ksr.com>
  16305.  
  16306. That's disgusting!  In a recent internal memo, I noted that "an
  16307. obfuscated Python constest is darned-near unimaginable".  Thanks for
  16308. making a liar out of me <wink>.
  16309.  
  16310. usually-able-to-manage-that-task-all-by-myself-ly y'rs  - tim
  16311. 
  16312. 
  16313. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  16314.     id AA09010 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 11:16:46 +0200
  16315. Received: by schelvis.cwi.nl with SMTP
  16316.     id AA01623 (5.65b/3.8/CWI-Amsterdam); Fri, 10 Sep 1993 11:16:45 +0200
  16317. Message-Id: <9309100916.AA01623=jack@schelvis.cwi.nl>
  16318. To: python-list@cwi.nl
  16319. Subject: Re: Thoughts and proposals about types and classes 
  16320. In-Reply-To: Message by Tim Peters <tim@ksr.com> ,
  16321.          Fri, 10 Sep 93 00:22:01 -0400 , <9309100422.AA10199@kaos.ksr.com> 
  16322. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  16323. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  16324. X-Last-Band-Seen: Kliek, Lyres (Sleepin, 2-9)
  16325. X-Mini-Review: Groovy sixties, man....
  16326. Date: Fri, 10 Sep 1993 11:16:45 +0200
  16327. From: Jack Jansen <Jack.Jansen@cwi.nl>
  16328.  
  16329. I have been thinking along the lines of something where you could ask
  16330. python 'would it be ok if I tried to do <this> with <that>?', which is
  16331. often what you use type() for.
  16332.  
  16333. An example:
  16334. def oldstyle(x):
  16335.     if type(x) in (type(()), type([])):
  16336.         for i in range(len(x)):
  16337.             print i, x[i]
  16338.     else:
  16339.         print x
  16340.  
  16341. def newstyle(x):
  16342.     if allowed(x[0]):
  16343.         for i in range(len(x)):
  16344.             print i, x[i]
  16345.     else:
  16346.         print x
  16347.  
  16348. This allowed() builtin would also obviate the need for the horrible
  16349. 'type(x) in (type(0), type(0L), type(0.0), etc)' constructs, by
  16350. allowing you to ask 'allowed(x+1)'.
  16351.  
  16352. There's a potential implementation problem with allowed(), though,
  16353. depending on how syntax analysis/execution work. Hmpf, where is Guido
  16354. when you need him...
  16355. --
  16356. Jack Jansen        | If I can't dance I don't want to be part of
  16357. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  16358. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  16359. 
  16360. 
  16361. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  16362.     id AA02430 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 22:11:18 +0200
  16363. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  16364.     id AA04522; Fri, 10 Sep 93 13:12:21 -0700
  16365. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  16366.     id AA26421; Fri, 10 Sep 93 12:08:08 -0700
  16367. Received: by ushqgw.sequent.com with Microsoft Mail
  16368.     id <2C90CF31@ushqgw.sequent.com>; Fri, 10 Sep 93 12:02:09 PDT
  16369. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  16370. To: jack <jack@cwi.nl>, python-list <python-list@cwi.nl>
  16371. Subject: Re: Thoughts and proposals about types and classes
  16372. Date: Fri, 10 Sep 93 09:48:00 PDT
  16373. Message-Id: <2C90CF31@ushqgw.sequent.com>
  16374. Encoding: 37 TEXT
  16375. X-Mailer: Microsoft Mail V3.0
  16376.  
  16377.  
  16378.  
  16379. | def oldstyle(x):
  16380. |         if type(x) in (type(()), type([])):
  16381. |                 for i in range(len(x)):
  16382. |                         print i, x[i]
  16383. |         else:
  16384. |                 print x
  16385.  
  16386. What about:
  16387.  
  16388. def altstyle(x)
  16389.     try:
  16390.      for i in range(len(x)):
  16391.          print i, x[i]
  16392.     except TypeError:
  16393.      print x
  16394.  
  16395. Here you would rely on the fact that len(x) would return TypeError on an 
  16396. unsized object. Or, the x[i] would return TypeError on an unsubscriptable 
  16397. object.
  16398.  
  16399. Either way, if Python would move towards a more pure OO paradigm, the 
  16400. subscription would become a method and you should be able the turn the 
  16401. allowed() into a simple check whether a method exists.
  16402.  
  16403. This brings to another point from the previous discussion with Steven. In 
  16404. most cases when you decide to forego on the type checking, you will run into 
  16405. either a TypeError or an AttributeError if the wrong object was passed in 
  16406. (as Jack points out). In a more pure OO environment with a perfect 
  16407. namespace, you would refer to a method that doesn't exist for that object 
  16408. (given the wrong object was passed in).
  16409.  
  16410. Disclaimer: With a "pure OO paradigm" I refer to an environment solely based 
  16411. on method lookup.
  16412.  
  16413.      -Jaap-
  16414. 
  16415. 
  16416. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  16417.     id AA28767 (5.65b/3.10/CWI-Amsterdam); Fri, 10 Sep 1993 20:48:33 +0200
  16418. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa21372;
  16419.           10 Sep 93 14:48 EDT
  16420. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  16421.     id AA17439; Fri, 10 Sep 1993 14:48:24 -0400
  16422. Date: Fri, 10 Sep 1993 14:48:24 -0400
  16423. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  16424. Message-Id: <199309101848.AA17439@elvis.med.Virginia.EDU>
  16425. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  16426. To: Jack Jansen <Jack.Jansen@cwi.nl>, python-list@cwi.nl
  16427. Subject: Re: Thoughts and proposals about types and classes
  16428.  
  16429. On Sep 10, 11:16, Jack Jansen wrote:
  16430. > I have been thinking along the lines of something where you could ask
  16431. > python 'would it be ok if I tried to do <this> with <that>?', which is
  16432. > often what you use type() for.
  16433.  [ ... ]
  16434. > This allowed() builtin would also obviate the need for the horrible
  16435. > 'type(x) in (type(0), type(0L), type(0.0), etc)' constructs, by
  16436. > allowing you to ask 'allowed(x+1)'.
  16437.  
  16438. Well - there is 'hasattr()', so for user classes you can check for
  16439. hasattr( thing, '__add__' ). The builtins types have to be a special 
  16440. case test. But contrary to my expectation, hasattr( 1, '__add__' )
  16441. didn't raise an exception and complain about not being a class or
  16442. instance - it just returned NO:
  16443.  
  16444. >>> hasattr( 1, '__add__' )
  16445. hasattr( 1, '__add__' )
  16446. 0
  16447. >>> 
  16448.  
  16449. But your syntax would HAVE to be a builtin operator to keep
  16450. allowed( x + 1 ) from evaluating "x + 1" first. I assume this
  16451. is the problem you are refering to below.
  16452.  
  16453. But the real problem is the one Tim brought up - if may be
  16454. "allowed" , but what does it _mean_, and how can you tell
  16455. until you try it? You want to know: (1) if "x" is either a 
  16456. builtin type that supports "+" or hasattr( x, '__add__' );
  16457. (2) can type x coerce '1' into the necessary type ? ; AND 
  16458. (3) does 'x + 1' REALLY MEAN what I think it does?. 
  16459.  
  16460. I thought I was getting around that by stating that 
  16461. "isnumeric(x) == True" means that the implementor of
  16462. it's class has PROMISED that "x + 1" does, in fact,
  16463. mean something reasonable. I now have some doubts that
  16464. it can do all that I had hoped. :-( 
  16465.  
  16466. > There's a potential implementation problem with allowed(), though,
  16467. > depending on how syntax analysis/execution work. Hmpf, where is Guido
  16468. > when you need him...
  16469.  
  16470. According to his vacation message, I think he is somewhere in the
  16471. USA right now. Guido - If you had only told us in advance, we would
  16472. have organized a fan-club meeting! 
  16473.  
  16474. - Steve M.
  16475. 
  16476. 
  16477. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  16478.     id AA05842 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 19:12:59 +0200
  16479. Received: by hermix.markv.com id ad15762; 13 Sep 93 10:10 PDT
  16480. From: Lance Ellinghouse <lance@markv.com>
  16481. X-Mailer: SCO System V Mail (version 3.2)
  16482. To: python-list@cwi.nl
  16483. Mmdf-Warning:  Unable to confirm address in preceding line at hermix.markv.com
  16484. Subject: question about exec() and compile()
  16485. Date: Sun, 12 Sep 93 16:02:53 PDT
  16486. Message-Id:  <9309121603.aa11689@hermix.markv.com>
  16487.  
  16488. I have a file that looks like this:
  16489. t = 1
  16490.  
  16491. def Test():
  16492.     print 't = ' + `t`
  16493.  
  16494. def test2():
  16495.     print 'calling Test()'
  16496.     Test()
  16497.  
  16498.  
  16499. I read in the file and want to execute test2().
  16500.  
  16501. So I do the following:
  16502.  
  16503. f = open('file','r')
  16504. a = f.read()
  16505. f.close()
  16506. a_c = compile(a,'<string>','exec')
  16507. local_ns = {}
  16508. global_ns = {}
  16509. exec(a_c,global_ns,local_ns)
  16510.  
  16511. Now if I dump local_ns, it shows 't', 'Test' and 'test2' as being
  16512. members of local_ns. global_ns is still empty.
  16513.  
  16514. Now how can I call test2? I have tried local_ns['test2']()
  16515. but it says it cannot find 'Test'
  16516.  
  16517. I CANNOT use 'import' as this code is actually part of a file
  16518. that cannot be run..
  16519.  
  16520. Any ideas?????
  16521.  
  16522. Thanks!
  16523. Lance Ellinghouse
  16524. lance@markv.com
  16525.  
  16526.  
  16527. 
  16528. 
  16529. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  16530.     id AA11787 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 05:54:32 +0200
  16531. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  16532.     id AA23064; Sun, 12 Sep 1993 23:51:32 -0400
  16533. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  16534.     id AA27612; Sun, 12 Sep 93 23:51:20 EDT
  16535. Received: by kaos.ksr.com (4.1/KSR-2.0)
  16536.     id AA21576; Sun, 12 Sep 93 23:51:00 EDT
  16537. Message-Id: <9309130351.AA21576@kaos.ksr.com>
  16538. To: Jack.Jansen@cwi.nl, sdm7g@virginia.edu, jaap@sequent.com
  16539. Subject: Re: Thoughts and proposals about types and classes
  16540. Cc: python-list@cwi.nl
  16541. Date: Sun, 12 Sep 93 23:50:59 -0400
  16542. From: Tim Peters <tim@ksr.com>
  16543.  
  16544. > [jack]
  16545. > def oldstyle(x):
  16546. >     if type(x) in (type(()), type([])):
  16547. >         for i in range(len(x)):
  16548. >             print i, x[i]
  16549. >     else:
  16550. >         print x
  16551. >
  16552. > def newstyle(x):
  16553. >     if allowed(x[0]):
  16554. >         for i in range(len(x)):
  16555. >             print i, x[i]
  16556. >     else:
  16557. >         print x
  16558.  
  16559. Is
  16560.  
  16561.     if allowed(expression):
  16562.         block1
  16563.     else:
  16564.         block2
  16565.  
  16566. different from (assuming 'ok' and 'dummy' are otherwise unused)
  16567.  
  16568.     ok = 1
  16569.     try:
  16570.         dummy = expression
  16571.     except (TypeError, AttributeError):
  16572.         ok = 0
  16573.  
  16574.     if ok:
  16575.         block1
  16576.     else:
  16577.         block2
  16578.  
  16579. ?  I suppose you don't actually want to evaluate 'expression', though, or
  16580. more likely specifically want _not_ to evaluate 'expression'.  I'm not
  16581. sure that's possible in general, though.  For example, even if x is an
  16582. instance of a class that supports a __sub__ method, there's no guarantee
  16583. that, e.g.,
  16584.  
  16585.     x-1
  16586.  
  16587. will end up invoking x.__sub__:  it depends on what x.__coerce__ decides
  16588. to do, and I doubt that's determinable, in general, without executing the
  16589. code.
  16590.  
  16591. I like the _idea_, because it gets directly at Guido's pragmatic "does
  16592. the object support the operation or not?" test.  I'm just dubious that it
  16593. can be made to work unless the argument is restricted to operations on
  16594. built-in objects (about whose behavior Python knows everything up front).
  16595.  
  16596. > [steve]
  16597. > >>> hasattr( 1, '__add__' )
  16598. > >>> 0
  16599.  
  16600. Cute!  Makes sense, though, eh?
  16601.  
  16602. Here's another one to ponder:
  16603.  
  16604. >>> class K:
  16605. ...   def __len__(self):
  16606. ...     return 12
  16607. ...
  16608. >>> temp=K(); hasattr(temp,'__len__'); len(temp)
  16609. 1
  16610. 12
  16611. >>> temp=K; hasattr(temp,'__len__'); len(temp)
  16612. 1
  16613. Stack backtrace (innermost last):
  16614.   File "<stdin>", line 1
  16615. TypeError: len() of unsized object
  16616. >>>
  16617.  
  16618. I.e., just because something has a __len__ attribute doesn't necessarily
  16619. mean you can apply the len function to it.  Presumably Jack's
  16620. 'allowed(len(K))' would have returned 0 here.
  16621.  
  16622. > [jaap]
  16623. > def altstyle(x)
  16624. >     try:
  16625. >      for i in range(len(x)):
  16626. >          print i, x[i]
  16627. >     except TypeError:
  16628. >      print x
  16629.  
  16630. I'm not clear on what Jack intended in the original example.
  16631.  
  16632. "oldstyle" did the "for i in range ..." bit for and only for tuples and
  16633. lists.
  16634.  
  16635. "newstyle" did it (I think) for and only for tuples, lists, and objects
  16636. that support __getitem__.  However, it would raise an exception for
  16637. objects that did support __getitem__ but not __len__.  In any case, it
  16638. doesn't do the same thing as "oldstyle" in all cases.
  16639.  
  16640. The code of which I asked "does this differ from oldstyle?" has somewhat
  16641. different behavior from both of those, and from "altstyle".  altstyle
  16642. hides what might be legitimate runtime type errors in an object's __len__
  16643. or __getitem__ method, and raises AttributeError for objects that don't
  16644. support __len__, or that do support a __len__ that returns a value > 0
  16645. but don't support __getitem__.
  16646.  
  16647.  
  16648. I don't mean to be irritatingly pedantic there <grin>; the primary real
  16649. point is that I think the problem we're trying to _solve_ with this stuff
  16650. is remarkably ill-defined (else at least _some_ pair of proposed
  16651. solutions would get close to having the same behavior <wink>).
  16652.  
  16653.  
  16654. > Here you would rely on the fact that len(x) would return TypeError on an
  16655. > unsized object. Or, the x[i] would return TypeError on an unsubscriptable
  16656. > object.
  16657.  
  16658. Just noting that the absence of __getitem__ yields AttributeError instead
  16659. of TypeError.
  16660.  
  16661. > Either way, if Python would move towards a more pure OO paradigm, the
  16662. > subscription would become a method and you should be able the turn the
  16663. > allowed() into a simple check whether a method exists.
  16664.  
  16665. See the "class K" example above for a context where this doesn't work as
  16666. hoped.  Is that the only exception?  Suspect it is.
  16667.  
  16668. instinctively-suspicious-of-"pure"-anything<wink>-ly y'rs  - tim
  16669.  
  16670. Tim Peters   tim@ksr.com
  16671. not speaking for Kendall Square Research Corp
  16672. 
  16673. 
  16674. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  16675.     id AA20337 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 11:51:10 +0200
  16676. Received: by schelvis.cwi.nl with SMTP
  16677.     id AA07253 (5.65b/3.8/CWI-Amsterdam); Mon, 13 Sep 1993 11:51:09 +0200
  16678. Message-Id: <9309130951.AA07253=jack@schelvis.cwi.nl>
  16679. To: python-list@cwi.nl
  16680. Subject: Re: Thoughts and proposals about types and classes 
  16681. In-Reply-To: Message by Tim Peters <tim@ksr.com> ,
  16682.          Sun, 12 Sep 93 23:50:59 -0400 , <9309130351.AA21576@kaos.ksr.com> 
  16683. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  16684. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  16685. X-Last-Band-Seen: Maroon Town (Melkweg, 4-9)
  16686. X-Mini-Review: Ska with a little jazz, soul, raggamixed in for good measure.
  16687. Date: Mon, 13 Sep 1993 11:51:08 +0200
  16688. From: Jack Jansen <Jack.Jansen@cwi.nl>
  16689.  
  16690. The point of my original example was indeed that the allowed()
  16691. expression was *not* evaluated, so that possible side-effects are no
  16692. problem. Otherwise the try/except construct woudl be good enough
  16693. (except for the fact that it doesn't really lead to well-structured
  16694. code in all cases).
  16695.  
  16696. There's a serious flaw in the whole idea, though, that was pointed out
  16697. by Dik Winter: the semantics are unclear. If I say "allowed(x+1)" it
  16698. is clear enough (even though there are implementation difficulties, as
  16699. Tim pointed out): check wether x has an add method that supports
  16700. integer arguments. If I say "allowed(foo())" ditto, I think: check that
  16701. foo is a function. If I say "allowed(foo()+1)" it becomes undecidable
  16702. without calling foo, since foo might return a different type depending
  16703. on the phase of the moon.
  16704.  
  16705. Even a restriction that you may use only one operator within the
  16706. allowed() expression is not good enough: you really want to be able to
  16707. say "allowed(len(x))", but here we're already testing two things:
  16708. besides testing wether x has a length (which is probably what we want
  16709. to test) we also test that len is a function. Moreover, we actually
  16710. use the semantics of len for the test we are really interested in, and
  16711. I can't see an easy way of doing that without executing len.
  16712.  
  16713. Oh well, another interesting idea down the drain,
  16714. --
  16715. Jack Jansen        | If I can't dance I don't want to be part of
  16716. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  16717. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  16718. 
  16719. 
  16720. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  16721.     id AA28336 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 15:38:42 +0200
  16722. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa13137;
  16723.           13 Sep 93 9:38 EDT
  16724. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  16725.     id AA15048; Mon, 13 Sep 1993 09:38:27 -0400
  16726. Date: Mon, 13 Sep 1993 09:38:27 -0400
  16727. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  16728. Message-Id: <199309131338.AA15048@elvis.med.Virginia.EDU>
  16729. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  16730. To: Jack Jansen <Jack.Jansen@cwi.nl>, python-list@cwi.nl
  16731. Subject: Re: Thoughts and proposals about types and classes
  16732.  
  16733. On Sep 13, 11:51, Jack Jansen wrote:
  16734. >
  16735. > There's a serious flaw in the whole idea, though, that was pointed out
  16736. > by Dik Winter: the semantics are unclear. If I say "allowed(x+1)" it
  16737. > is clear enough (even though there are implementation difficulties, as
  16738. > Tim pointed out): check wether x has an add method that supports
  16739. > integer arguments. If I say "allowed(foo())" ditto, I think: check that
  16740. > foo is a function. If I say "allowed(foo()+1)" it becomes undecidable
  16741. > without calling foo, since foo might return a different type depending
  16742. > on the phase of the moon.
  16743.  
  16744. I think what you have stumbled across here, Jack, is the probability
  16745. that the sort of feature we've been talking about may only be able
  16746. to be implemented ( of if implemented, used ) in a limited fashion
  16747. in a dynamic/loosely typed O-O language. It might actually work in
  16748. a compiled, strongly-typed, type-inference class based type language,
  16749. where allowed( foo()+1 ) would most often turn into a compile time
  16750. consistency check, and only turn into a runtime test when there was
  16751. not enough context to determine what set of objects 'foo' could
  16752. possibly be bound to. 
  16753.  
  16754. > Oh well, another interesting idea down the drain,
  16755.  
  16756. This is the 2nd time I've tried to recall a Cardelli paper
  16757. about the addition of type 'Dynamic' to Modula-3 : the 
  16758. question came up in another forum about how much checking
  16759. was done at compile time and how much at run time. 
  16760. (  Dynamic was an attempt to add a dynamic run time typing
  16761. to a language that was strongly compile time typed in a 
  16762. SAFE manner - i.e. without breaking all of the type 
  16763. checking with the contagion of uncertainty. ) I know 
  16764. Guido has stated that Modula-3 was one of the inspirations
  16765. for python - perhaps he will have some comment when he
  16766. get back.
  16767.  
  16768. - Steve M.
  16769. 
  16770. 
  16771. Received: from hydra.acs.uci.edu by charon.cwi.nl with SMTP
  16772.     id AA02316 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 17:25:10 +0200
  16773. Received: from localhost by hydra.acs.uci.edu with SMTP id AA07568
  16774.   (5.65c/IDA-1.4.4 for <python-list@cwi.nl>); Mon, 13 Sep 1993 08:24:57 -0700
  16775. Message-Id: <199309131524.AA07568@hydra.acs.uci.edu>
  16776. To: Tim Peters <tim@ksr.com>
  16777. Cc: python-list@cwi.nl
  16778. Subject: Re: Thoughts and proposals about types and classes 
  16779. In-Reply-To: Your message of "Sun, 12 Sep 93 23:50:59 EDT."
  16780.              <9309130351.AA21576@kaos.ksr.com> 
  16781. Date: Mon, 13 Sep 93 08:24:54 -0700
  16782. From: Dan Stromberg - OAC-DCS <strombrg@hydra.acs.uci.edu>
  16783.  
  16784.  
  16785. It would seem one way of determining if a failure to execute a method
  16786. with a specific type is:
  16787.  
  16788. 1) due to the lack of that method presence at all
  16789.  
  16790.   or 
  16791.  
  16792. 2) due to the lack of an appropriate coercion
  16793.  
  16794. ...would be to provide one or two constants with each numeric type.
  16795. "zero" and "one" would be good candidates, "one" alone being more
  16796. useful than "zero" alone.
  16797.  
  16798. Of course, that means adding a constant or two to a fair number of
  16799. types, but...
  16800.  
  16801. Given the presence of a constant "one", and operators for addition and
  16802. multiplication, it would probably be possible to provide a fairly
  16803. efficient, inheritable routine for converting ascii to a new numeric
  16804. type...
  16805.  
  16806. In message <9309130351.AA21576@kaos.ksr.com> you write:
  16807. >> [jack]
  16808. >> def oldstyle(x):
  16809. >>     if type(x) in (type(()), type([])):
  16810. >>         for i in range(len(x)):
  16811. >>             print i, x[i]
  16812. >>     else:
  16813. >>         print x
  16814. >>
  16815. >> def newstyle(x):
  16816. >>     if allowed(x[0]):
  16817. >>         for i in range(len(x)):
  16818. >>             print i, x[i]
  16819. >>     else:
  16820. >>         print x
  16821. >
  16822. >Is
  16823. >
  16824. >    if allowed(expression):
  16825. >        block1
  16826. >    else:
  16827. >        block2
  16828. >
  16829. >different from (assuming 'ok' and 'dummy' are otherwise unused)
  16830. >
  16831. >    ok = 1
  16832. >    try:
  16833. >        dummy = expression
  16834. >    except (TypeError, AttributeError):
  16835. >        ok = 0
  16836. >
  16837. >    if ok:
  16838. >        block1
  16839. >    else:
  16840. >        block2
  16841. >
  16842. >?  I suppose you don't actually want to evaluate 'expression', though, or
  16843. >more likely specifically want _not_ to evaluate 'expression'.  I'm not
  16844. >sure that's possible in general, though.  For example, even if x is an
  16845. >instance of a class that supports a __sub__ method, there's no guarantee
  16846. >that, e.g.,
  16847. >
  16848. >    x-1
  16849. >
  16850. >will end up invoking x.__sub__:  it depends on what x.__coerce__ decides
  16851. >to do, and I doubt that's determinable, in general, without executing the
  16852. >code.
  16853. >
  16854. >I like the _idea_, because it gets directly at Guido's pragmatic "does
  16855. >the object support the operation or not?" test.  I'm just dubious that it
  16856. >can be made to work unless the argument is restricted to operations on
  16857. >built-in objects (about whose behavior Python knows everything up front).
  16858. >
  16859. >> [steve]
  16860. >> >>> hasattr( 1, '__add__' )
  16861. >> >>> 0
  16862. >
  16863. >Cute!  Makes sense, though, eh?
  16864. >
  16865. >Here's another one to ponder:
  16866. >
  16867. >>>> class K:
  16868. >...   def __len__(self):
  16869. >...     return 12
  16870. >...
  16871. >>>> temp=K(); hasattr(temp,'__len__'); len(temp)
  16872. >1
  16873. >12
  16874. >>>> temp=K; hasattr(temp,'__len__'); len(temp)
  16875. >1
  16876. >Stack backtrace (innermost last):
  16877. >  File "<stdin>", line 1
  16878. >TypeError: len() of unsized object
  16879. >>>>
  16880. >
  16881. >I.e., just because something has a __len__ attribute doesn't necessarily
  16882. >mean you can apply the len function to it.  Presumably Jack's
  16883. >'allowed(len(K))' would have returned 0 here.
  16884. >
  16885. >> [jaap]
  16886. >> def altstyle(x)
  16887. >>     try:
  16888. >>      for i in range(len(x)):
  16889. >>          print i, x[i]
  16890. >>     except TypeError:
  16891. >>      print x
  16892. >
  16893. >I'm not clear on what Jack intended in the original example.
  16894. >
  16895. >"oldstyle" did the "for i in range ..." bit for and only for tuples and
  16896. >lists.
  16897. >
  16898. >"newstyle" did it (I think) for and only for tuples, lists, and objects
  16899. >that support __getitem__.  However, it would raise an exception for
  16900. >objects that did support __getitem__ but not __len__.  In any case, it
  16901. >doesn't do the same thing as "oldstyle" in all cases.
  16902. >
  16903. >The code of which I asked "does this differ from oldstyle?" has somewhat
  16904. >different behavior from both of those, and from "altstyle".  altstyle
  16905. >hides what might be legitimate runtime type errors in an object's __len__
  16906. >or __getitem__ method, and raises AttributeError for objects that don't
  16907. >support __len__, or that do support a __len__ that returns a value > 0
  16908. >but don't support __getitem__.
  16909. >
  16910. >
  16911. >I don't mean to be irritatingly pedantic there <grin>; the primary real
  16912. >point is that I think the problem we're trying to _solve_ with this stuff
  16913. >is remarkably ill-defined (else at least _some_ pair of proposed
  16914. >solutions would get close to having the same behavior <wink>).
  16915. >
  16916. >
  16917. >> Here you would rely on the fact that len(x) would return TypeError on an
  16918. >> unsized object. Or, the x[i] would return TypeError on an unsubscriptable
  16919. >> object.
  16920. >
  16921. >Just noting that the absence of __getitem__ yields AttributeError instead
  16922. >of TypeError.
  16923. >
  16924. >> Either way, if Python would move towards a more pure OO paradigm, the
  16925. >> subscription would become a method and you should be able the turn the
  16926. >> allowed() into a simple check whether a method exists.
  16927. >
  16928. >See the "class K" example above for a context where this doesn't work as
  16929. >hoped.  Is that the only exception?  Suspect it is.
  16930. >
  16931. >instinctively-suspicious-of-"pure"-anything<wink>-ly y'rs  - tim
  16932. >
  16933. >Tim Peters   tim@ksr.com
  16934. >not speaking for Kendall Square Research Corp
  16935.  
  16936. Dan Stromberg - OAC/DCS                         strombrg@uci.edu
  16937. 
  16938. 
  16939. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  16940.     id AA06586 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 19:30:47 +0200
  16941. To: lance@markv.com
  16942. Cc: python-list@cwi.nl
  16943. In-Reply-To: <9309121603.aa11689@hermix.markv.com> (message from Lance Ellinghouse on Sun, 12 Sep 93 16:02:53 PDT)
  16944. Subject: Re: question about exec() and compile()
  16945. X-Organization: Mark V Systems Ltd.
  16946. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  16947. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  16948. Date: Mon, 13 Sep 93 10:29:22 PDT
  16949. From: lance@markv.com
  16950. Sender: lance@markv.com
  16951. Message-Id:  <9309131029.aa17663@hermix.markv.com>
  16952. Source-Info:  From (or Sender) name not authenticated.
  16953.  
  16954.  
  16955. I figured out a hack to allow me to do what I want....
  16956. I just have to add 1 line of code as shown below..
  16957.  
  16958.  > I have a file that looks like this:
  16959.  > t = 1
  16960.  > 
  16961.  > def Test():
  16962.  >     print 't = ' + `t`
  16963.  > 
  16964.  > def test2():
  16965.  >     print 'calling Test()'
  16966.  >     Test()
  16967.  > 
  16968.  > 
  16969.  > I read in the file and want to execute test2().
  16970.  > 
  16971.  > So I do the following:
  16972.  > 
  16973.  > f = open('file','r')
  16974.  > a = f.read()
  16975.  > f.close()
  16976.  > a_c = compile(a,'<string>','exec')
  16977.  > local_ns = {}
  16978.  > global_ns = {}
  16979.  > exec(a_c,global_ns,local_ns)
  16980.  
  16981.    exec(a_c,local_ns,local_ns)
  16982.  
  16983.  now I can say:
  16984.    local_ns['test2']()
  16985.  
  16986.  and the result will be
  16987.  
  16988. calling Test()
  16989. t = 1
  16990.  
  16991.  
  16992. This is what I wanted to be able to do.. 
  16993. Sorry for wasting net-bandwidth on this..
  16994.  
  16995. --
  16996.  
  16997. Lance Ellinghouse           lance@markv.com
  16998.  
  16999. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  17000. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  17001. You can receive my Public Key by `finger lance@mark.com`
  17002. 
  17003. 
  17004. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  17005.     id AA09030 (5.65b/3.10/CWI-Amsterdam); Mon, 13 Sep 1993 20:23:27 +0200
  17006. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa02171;
  17007.           13 Sep 93 14:23 EDT
  17008. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  17009.     id AA13074; Mon, 13 Sep 1993 14:23:19 -0400
  17010. Date: Mon, 13 Sep 1993 14:23:19 -0400
  17011. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  17012. Message-Id: <199309131823.AA13074@elvis.med.Virginia.EDU>
  17013. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  17014. To: python-list@cwi.nl
  17015. Subject: My other pet python peeve - .sort(),.reverse(), etc. return None
  17016.  
  17017.  
  17018. Although I'm generally a python fan and booster, there are a couple
  17019. of quirks in the language that I sometimes find frustrating. ( Tim 
  17020. and I were discussing a few of them, offline, in a thread started
  17021. by my 'obfuscated python' post. ) 
  17022.  
  17023. Some of them may be unavoidable features of other aspects of python's 
  17024. syntax and/or model of execution. But one that often catches me, 
  17025. because it seems (to me) rather arbitrary is the fact the some of 
  17026. the list methods, like .sort, .reverse, .append, all return None. 
  17027. I would think it preferable to return the new list. 
  17028.  
  17029. Why? 
  17030. [ I know I may have to await Guido's return to get an authoritive
  17031. answer. ] 
  17032.  
  17033. The only reason that comes to mind, is that that design feature was
  17034. intended as a reminder that those methods are not, strictly speaking,
  17035. _functions_, but _procedures_ that produce side effects: "whatch out! - 
  17036. x.sort() is going to change the value of x - not just return a NEW 
  17037. sequence!" ) 
  17038.  
  17039. To a C and/or Lisp programmer, who is used to the idea that everything
  17040. is a function - some are not PURE side-effect-less functions, and some
  17041. don't return anything useful, but they are all functions, this does
  17042. not seem a very intuitive distinction. ( Maybe it *does( if you are 
  17043. comming from Modula-[23]. I don't know. )
  17044.  
  17045. What's more: there is nothing to stop you from SAYING:
  17046.  
  17047. [ 1,2,3,4 ].sort()
  17048. [ 1,2,3,4 ].append( 5 )
  17049. [ 1,2,3,4 ].reverse()
  17050.  
  17051. all of which, of course, return None, NOT the result of applying 
  17052. method to the anonymous sequence. ( An exception would seem to be
  17053. called for here, although, I don't expect that .sort() has any way
  17054. in hell of KNOWING that it is being called on an anonymous list. ) 
  17055.  
  17056. So I can't say, for example:
  17057.  
  17058.    string.split( file.readline() ).sort() 
  17059.  
  17060. [ In practice, lack of append() returning a value isn't usually a 
  17061.   problem: the expression is typically part of a 'return' or an
  17062.   assignment, so, for example: "return string.join( list ) + '\n'" 
  17063.   is the typical idiom. ] 
  17064.  
  17065. I know this isn't Guido's style. But it's *MY* style, and I'm
  17066. fond of it, ( as you can probably tell from my 'obfuscated python' ;-)
  17067. and it *seems* (IMHO) to be a rather _arbitrary_ restriction. 
  17068. ( And I can't even think of some likely + reasonable code that would
  17069.  be broken by the change. I can't think that anyone ever *tests* 
  17070.  that "list.sort() == None" - since that is, in fact, the only
  17071.  possible return value. ) 
  17072.  
  17073.  
  17074. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  17075. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  17076. 
  17077. 
  17078. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  17079.     id AA19555 (5.65b/3.10/CWI-Amsterdam); Tue, 14 Sep 1993 01:37:27 +0200
  17080. To: python-list@cwi.nl
  17081. Subject: purify report from testall run
  17082. X-Signed: PGP-Attached-clearsig-2-3,
  17083.     iQCVAgUBLJUD12nDnXuZ0ONVAQF7KwP/T07qUgZj4CfbZaGvPmRLOiJuzxP5vRb5
  17084.     up+PAPH4MCU/GUFu3hnSEyP3VFThLDD2Cv3ooK8VKCz4peIxOrvyMGUQ7wpOyFoW
  17085.     dWlVNkt1KU+2W2C3THBmAamA3Yq5Nz42MCz3BGhIOXRKPbRa/q7mNu4ikFDsPFCy
  17086.     D64bVHg5/iE=
  17087. X-Organization: Mark V Systems Ltd.
  17088. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  17089. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  17090. Date: Mon, 13 Sep 93 16:36:15 PDT
  17091. From: lance@markv.com
  17092. Sender: lance@markv.com
  17093. Message-Id:  <9309131636.aa10022@hermix.markv.com>
  17094. Source-Info:  From (or Sender) name not authenticated.
  17095.  
  17096. I was curious about memory usage in Python...
  17097. I compiled python for purify and ran 'testall' to give it a good test..
  17098.  
  17099. here is the pyrify report.. 
  17100.  
  17101. Purify'd python  (pid 19353) 
  17102.  Purify 2 (C) 1990-93 Pure Software Inc.  Patents Pending.
  17103.  Contact us at:  support@pure.com or (408) 720 1600.
  17104.  In Europe:  support@pts.co.uk or (+44) 61 776 4499.
  17105.  Purify checking enabled.
  17106.  
  17107. ****  Purify'd python  (pid 19353)  ****
  17108. Purify (umr): uninitialized memory read:
  17109.   * This is occurring while in:
  17110.     initstrop    [line 385, stropmodule.c, pc=0x46b1c]
  17111.     init_builtin [line 403, import.c, pc=0x753fc]
  17112.     import_module [line 341, import.c, pc=0x74ee4]
  17113.     eval_code    [line 1202, ceval.c, pc=0x526c0]
  17114.     get_module   [line 317, import.c, pc=0x74cb8]
  17115.     load_module  [line 327, import.c, pc=0x74da8]
  17116.   * Reading 4 bytes from 0xf7ffd994 on the stack
  17117.     This is local variable "s" in function initstrop.
  17118. >>> 
  17119. Purify: Searching for all memory leaks...
  17120. There are 3967 leaked bytes (7.98% of the 49683 allocated bytes in the heap)
  17121.  
  17122.       28 bytes (2 times) + 
  17123.       27 + 26 (4 times) + 24 (9 times) + 23 (8 times) + 22 (7 times) + 
  17124.       21 (14 times) + 20 (6 times) + 18 (16 times) + 17 (3 times).     Last memory leak at 0x2324e0 
  17125. Report (mlk): 1494 total bytes lost, malloc called from:
  17126.     newstringobject [line 52, stringobject.c, pc=0x3541c]
  17127.     compile      [line 2278, compile.c, pc=0x6cbb4]
  17128.     com_funcdef  [line 1774, compile.c, pc=0x6a434]
  17129.     com_node     [line 1845, compile.c, pc=0x6ac88]
  17130.     com_node     [line 1871, compile.c, pc=0x6ae20]
  17131.     com_node     [line 1856, compile.c, pc=0x6ace4]
  17132.  
  17133.       16 bytes + 15 (8 times) + 14 (8 times) + 13 (15 times) + 
  17134.       12 (11 times) + 11   Last memory leak at 0x141258 
  17135. Report (mlk): 586 total bytes lost, malloc called from:
  17136.     initmodule   [line 45, modsupport.c, pc=0x23b18]
  17137.     initposix    [line 1232, posixmodule.c, pc=0x2ba38]
  17138.     init_builtin [line 403, import.c, pc=0x753fc]
  17139.     import_module [line 341, import.c, pc=0x74ee4]
  17140.     eval_code    [line 1202, ceval.c, pc=0x526c0]
  17141.     eval_node    [line 323, pythonrun.c, pc=0x2e1a0]
  17142.  
  17143.       19 bytes + 18 (2 times) + 17 (4 times) + 16 (3 times) + 15 (5 times) + 
  17144.       14 (7 times) + 13 (13 times) + 12   Last memory leak at 0x1379d0 
  17145. Report (mlk): 525 total bytes lost, malloc called from:
  17146.     initmodule   [line 45, modsupport.c, pc=0x23b18]
  17147.     initbuiltin  [line 890, bltinmodule.c, pc=0x4d7c4]
  17148.     initall      [line 77, pythonrun.c, pc=0x2cca4]
  17149.     main         [line 133, pythonmain.c, pc=0x1a380]
  17150.     start        [crt0.o, pc=0x2064]
  17151.  
  17152.       27 bytes + 26 (2 times) + 24 + 22 + 21 (8 times) + 20 (3 times).     Last memory leak at 0x1c26e0 
  17153. Report (mlk): 353 total bytes lost, malloc called from:
  17154.     __gnu_compiled_c [line 34, stringobject.c, pc=0x352f0]
  17155.     r_object     [line 334, marshal.c, pc=0x212fc]
  17156.     r_object     [line 385, marshal.c, pc=0x218b0]
  17157.     r_object     [line 360, marshal.c, pc=0x215b4]
  17158.     r_object     [line 382, marshal.c, pc=0x21850]
  17159.     rd_object    [line 422, marshal.c, pc=0x21d00]
  17160.  
  17161.       12 bytes (5 times) + 11 (11 times) + 10 (6 times).     Last memory leak at 0x159e40 
  17162. Report (mlk): 241 total bytes lost, malloc called from:
  17163.     initmodule   [line 45, modsupport.c, pc=0x23b18]
  17164.     initmath     [line 221, mathmodule.c, pc=0x23718]
  17165.     init_builtin [line 403, import.c, pc=0x753fc]
  17166.     import_module [line 341, import.c, pc=0x74ee4]
  17167.     eval_code    [line 1202, ceval.c, pc=0x526c0]
  17168.     get_module   [line 317, import.c, pc=0x74cb8]
  17169.  
  17170.       22 bytes (3 times) + 21 (5 times) + 20 (2 times) + 19   Last memory leak at 0x13b508 
  17171. Report (mlk): 230 total bytes lost, malloc called from:
  17172.     newstringobject [line 52, stringobject.c, pc=0x3541c]
  17173.     list_builtin_module_names [line 165, sysmodule.c, pc=0x3afc4]
  17174.     initsys      [line 195, sysmodule.c, pc=0x3b428]
  17175.     initall      [line 78, pythonrun.c, pc=0x2ccac]
  17176.     main         [line 133, pythonmain.c, pc=0x1a380]
  17177.     start        [crt0.o, pc=0x2064]
  17178.  
  17179.       17 bytes (2 times) + 16 + 14 + 13 (2 times) + 12 (2 times) + 
  17180.       11   Last memory leak at 0x1437c0 
  17181. Report (mlk): 125 total bytes lost, malloc called from:
  17182.     initmodule   [line 45, modsupport.c, pc=0x23b18]
  17183.     inittime     [line 365, timemodule.c, pc=0x3cb7c]
  17184.     init_builtin [line 403, import.c, pc=0x753fc]
  17185.     import_module [line 341, import.c, pc=0x74ee4]
  17186.     eval_code    [line 1202, ceval.c, pc=0x526c0]
  17187.     get_module   [line 317, import.c, pc=0x74cb8]
  17188.  
  17189.       19 bytes + 18 + 16 + 13 (5 times).     Last memory leak at 0x1fc230 
  17190. Report (mlk): 118 total bytes lost, malloc called from:
  17191.     initmodule   [line 45, modsupport.c, pc=0x23b18]
  17192.     initstrop    [line 376, stropmodule.c, pc=0x46a2c]
  17193.     init_builtin [line 403, import.c, pc=0x753fc]
  17194.     import_module [line 341, import.c, pc=0x74ee4]
  17195.     eval_code    [line 1202, ceval.c, pc=0x526c0]
  17196.     get_module   [line 317, import.c, pc=0x74cb8]
  17197.  
  17198.       18 bytes (2 times) + 17 (4 times).     Last memory leak at 0x222e48 
  17199. Report (mlk): 104 total bytes lost, malloc called from:
  17200.     newstringobject [line 52, stringobject.c, pc=0x3541c]
  17201.     compile      [line 2278, compile.c, pc=0x6cbb4]
  17202.     com_classdef [line 1821, compile.c, pc=0x6a930]
  17203.     com_node     [line 1848, compile.c, pc=0x6acb0]
  17204.     com_node     [line 1871, compile.c, pc=0x6ae20]
  17205.     com_node     [line 1856, compile.c, pc=0x6ace4]
  17206.  
  17207. Report (mlk): 53 bytes at 0x13bab0 lost, malloc called from:
  17208.     realloc      [p5.o, pc=0x4a24]
  17209.     ins1         [line 133, listobject.c, pc=0x7f74c]
  17210.     addlistitem  [line 173, listobject.c, pc=0x7fb40]
  17211.     list_builtin_module_names [line 168, sysmodule.c, pc=0x3b000]
  17212.     initsys      [line 195, sysmodule.c, pc=0x3b428]
  17213.     initall      [line 78, pythonrun.c, pc=0x2ccac]
  17214.  
  17215.       16 bytes + 14 + 10   Last memory leak at 0x13a800 
  17216. Report (mlk): 40 total bytes lost, malloc called from:
  17217.     initmodule   [line 45, modsupport.c, pc=0x23b18]
  17218.     initsys      [line 180, sysmodule.c, pc=0x3b1f0]
  17219.     initall      [line 78, pythonrun.c, pc=0x2ccac]
  17220.     main         [line 133, pythonmain.c, pc=0x1a380]
  17221.     start        [crt0.o, pc=0x2064]
  17222.  
  17223.       19 bytes (2 times).     Last memory leak at 0x1408b8 
  17224. Report (mlk): 38 total bytes lost, malloc called from:
  17225.     __gnu_compiled_c [line 34, stringobject.c, pc=0x352f0]
  17226.     do_mkvalue   [line 489, modsupport.c, pc=0x26330]
  17227.     do_mktuple   [line 422, modsupport.c, pc=0x257f8]
  17228.     do_mkvalue   [line 448, modsupport.c, pc=0x25d1c]
  17229.     vmkvalue     [line 556, modsupport.c, pc=0x26690]
  17230.     mkvalue      [line 537, modsupport.c, pc=0x26568]
  17231.  
  17232. Report (mlk): 24 bytes at 0x140860 lost, malloc called from:
  17233.     newtupleobject [line 39, tupleobject.c, pc=0x3cff0]
  17234.     do_mktuple   [line 419, modsupport.c, pc=0x25788]
  17235.     do_mkvalue   [line 448, modsupport.c, pc=0x25d1c]
  17236.     vmkvalue     [line 556, modsupport.c, pc=0x26690]
  17237.     mkvalue      [line 537, modsupport.c, pc=0x26568]
  17238.     inittime     [line 394, timemodule.c, pc=0x3ce04]
  17239.  
  17240. Report (mlk): 17 bytes at 0x1f60d8 lost, malloc called from:
  17241.     __gnu_compiled_c [line 34, stringobject.c, pc=0x352f0]
  17242.     r_object     [line 334, marshal.c, pc=0x212fc]
  17243.     r_object     [line 385, marshal.c, pc=0x218b0]
  17244.     rd_object    [line 422, marshal.c, pc=0x21d00]
  17245.     get_module   [line 232, import.c, pc=0x745c8]
  17246.     reload_module [line 364, import.c, pc=0x750e4]
  17247.  
  17248. Report (mlk): 16 bytes at 0x13b168 lost, malloc called from:
  17249.     __gnu_compiled_c [line 47, listobject.c, pc=0x7eff4]
  17250.     list_builtin_module_names [line 160, sysmodule.c, pc=0x3af3c]
  17251.     initsys      [line 195, sysmodule.c, pc=0x3b428]
  17252.     initall      [line 78, pythonrun.c, pc=0x2ccac]
  17253.     main         [line 133, pythonmain.c, pc=0x1a380]
  17254.     start        [crt0.o, pc=0x2064]
  17255.  
  17256. Report (mlk): 3 bytes at 0x2187c8 lost, malloc called from:
  17257.     parsetok     [line 157, parsetok.c, pc=0x887cc]
  17258.     parsestring  [line 56, parsetok.c, pc=0x87e50]
  17259.     parse_string [line 372, pythonrun.c, pc=0x2e47c]
  17260.     run_string   [line 270, pythonrun.c, pc=0x2de1c]
  17261.     exec_eval    [line 224, bltinmodule.c, pc=0x4a148]
  17262.     builtin_exec [line 240, bltinmodule.c, pc=0x4a200]
  17263.  
  17264.  
  17265.  Purify Heap Analysis (combining suppressed and unsuppressed chunks)
  17266.  
  17267.                          Chunks      Bytes
  17268.               Leaked        232       3967
  17269.   Potentially Leaked          0          0
  17270.               In-Use        270      45716
  17271.   ----------------------------------------
  17272.      Total Allocated        502      49683
  17273.  
  17274. ****  Purify'd python  (pid 19353)  ****
  17275.   * 1 access error.
  17276.   * Basic memory usage:
  17277.       983032 code
  17278.       275936 data/bss
  17279.      1425424 heap
  17280.         3208 stack
  17281.   * Shared library memory usage:
  17282.       696320 libc_pure_200.so.1.7    (shared code)
  17283.        16384 libc_pure_200.so.1.7    (private data)
  17284.         8192 libinternal_stubs.so.1.0    (shared code)
  17285.         8192 libinternal_stubs.so.1.0    (private data)
  17286.  
  17287.  
  17288.  
  17289.  
  17290. - --
  17291.  
  17292. Lance Ellinghouse           lance@markv.com
  17293.  
  17294. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  17295. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  17296. You can receive my Public Key by `finger lance@mark.com`
  17297. 
  17298. 
  17299. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  17300.     id AA23091 (5.65b/3.10/CWI-Amsterdam); Tue, 14 Sep 1993 05:06:21 +0200
  17301. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  17302.     id AA08564; Mon, 13 Sep 1993 23:03:57 -0400
  17303. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  17304.     id AA23600; Mon, 13 Sep 93 23:03:41 EDT
  17305. Received: by kaos.ksr.com (4.1/KSR-2.0)
  17306.     id AA28191; Mon, 13 Sep 93 23:01:53 EDT
  17307. Message-Id: <9309140301.AA28191@kaos.ksr.com>
  17308. To: sdm7g@virginia.edu, python-list@cwi.nl
  17309. Subject: Re: My other pet python peeve - .sort(),.reverse(), etc. return None
  17310. Date: Mon, 13 Sep 93 23:01:52 -0400
  17311. From: Tim Peters <tim@ksr.com>
  17312.  
  17313. > [steve, noting that [].sort(), [].reverse(), ..., return None instead
  17314. >  of the modified object, making natural-enough constructs like
  17315. >    string.split( file.readline() ).sort()
  17316. >  surprising
  17317. > ]
  17318. > ...
  17319. > ( And I can't even think of some likely + reasonable code that would
  17320. >  be broken by the change. ...
  17321.  
  17322. For a reasonable counterexample, how about every program you have <0.1
  17323. grin>?  That is, whenever you have
  17324.  
  17325.     thing.sort()
  17326.  
  17327. now, it yields None, and _because_ it yields None specifically, Python
  17328. doesn't print the value:
  17329.  
  17330. >>> [1,2,3]  # non-None result is printed
  17331. [1, 2, 3]
  17332. >>> None     # None result is not printed
  17333. >>>
  17334.  
  17335. So if thing.sort() (or reverse or append) were to return the sorted
  17336. (reversed, appended) object instead, every existing line like that would
  17337. start producing output.  Yeech!
  17338.  
  17339. I suspect Jaap would disagree, but as a pragmatic matter I like Python's
  17340. mix of functional, procedural, and OO flavors -- different bullets for
  17341. different beasts.  It's hard to judge which flavor is best for each
  17342. built-in concept, though.
  17343.  
  17344. Anyway, here's a cheap (& I dare say obvious <wink>) workaround I use.
  17345. Haven't upgraded this since [].sort() grew its optional comparison-
  17346. function argument, but that's clearly easy to add:
  17347.  
  17348. def sort(thing):
  17349.     thing.sort()
  17350.     return thing
  17351.  
  17352. Then, e.g.,
  17353.    process(sort(string.split( file.readline() )))
  17354.  
  17355. works fine.  I too dislike the
  17356.  
  17357.     temp = string.split( file.readline() )
  17358.     temp.sort()
  17359.     process( temp )
  17360.  
  17361. alternative.
  17362.  
  17363. non-decreasing-ly y'rs  - tim
  17364.  
  17365. Tim Peters   tim@ksr.com
  17366. not speaking for Kendall Square Research Corp
  17367. 
  17368. 
  17369. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  17370.     id AA25037 (5.65b/3.10/CWI-Amsterdam); Tue, 14 Sep 1993 09:08:27 +0200
  17371. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa05094;
  17372.           14 Sep 93 3:08 EDT
  17373. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  17374.     id AA11742; Tue, 14 Sep 1993 03:08:18 -0400
  17375. Date: Tue, 14 Sep 1993 03:08:18 -0400
  17376. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  17377. Message-Id: <199309140708.AA11742@elvis.med.Virginia.EDU>
  17378. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  17379. To: Tim Peters <tim@ksr.com>, sdm7g@virginia.edu, python-list@cwi.nl
  17380. Subject: Re: My other pet python peeve - .sort(),.reverse(), etc. return None
  17381.  
  17382. On Sep 13, 23:01, Tim Peters wrote:
  17383. > > ...
  17384. > > ( And I can't even think of some likely + reasonable code that would
  17385. > >  be broken by the change. ...
  17386. > For a reasonable counterexample, how about every program you have <0.1
  17387. > grin>?  That is, whenever you have
  17388. >     thing.sort()
  17389. > now, it yields None, and _because_ it yields None specifically, Python
  17390. > doesn't print the value:
  17391. > So if thing.sort() (or reverse or append) were to return the sorted
  17392. > (reversed, appended) object instead, every existing line like that would
  17393. > start producing output.  Yeech!
  17394.  
  17395. O.K. 
  17396. So, besides that ONE *little* problem   <embarassed grin :->
  17397. what's wrong? 
  17398.  
  17399.  
  17400. And yes - the obvious work around has ocurred to me, and I've used it
  17401. a few times. But if *I* feel the need to redefine sort, and _if_ you and
  17402. others also feel it is awkward ( I don't know if that IS the case ),
  17403. then I'd say it IS a mis-feature. ( though clearly not as easy to fix
  17404. transparently as I had thought. )
  17405.  
  17406.  Honestly - this has not been a major problem for me. One reasone I'm
  17407.  bringing it up is that python release 0.9.9, as well as the "Great 
  17408.  Renaming" has me thinking about becomming a more active "Python 
  17409.  Evangelist".  We've been through a couple of syntax changes, but I
  17410.  have sort of assumed that by the time we get to version 1.0 release,
  17411.  the language, ( if not the implementation ) will essentially be 
  17412.  stable. ( with perhaps some upwardly compatible extensions. ) 
  17413.  So the approach of that event has made me a bit "picky" - I feel
  17414.  it's "speak now or forever hold your peace!" And I feel that this
  17415.  is one of the "non-intuitive" features of python that new users 
  17416.  might stumble over a few times. 
  17417.  
  17418. [ The same goes for my pickiness about "array.read( file, count )" ]
  17419.  
  17420. Which is also why I'm concerned with the normal default bahaviour,
  17421. rather than how I can fix it for me. I'm not sure if I can 
  17422. transparently change the default behaviour without having to 
  17423. remember to import MY definitions - maybe I can do it with an
  17424. init file, so that it gets imported into the global namespace.
  17425. Certainly, I could change C source and rebuild *MY* copy of
  17426. python to do what *I* want. But then I'ld just get used to 
  17427. ( and learn to take for granted ) what for everyone ELSE is 
  17428. the wrong behaviour. 
  17429.  
  17430. I don't think it bugs me THAT much, that I'ld become an island
  17431. among python users. ( Any idea how many of us there are? ) 
  17432.  
  17433. [ Although, I might be tempted to try it as an experiment, to
  17434.  see HOW many pieces of code the change might actually break,
  17435.  and how badly. ] 
  17436.  
  17437.  
  17438. - Steve M.
  17439. 
  17440. 
  17441. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  17442.     id AA26157 (5.65b/3.10/CWI-Amsterdam); Tue, 14 Sep 1993 10:32:49 +0200
  17443. Received: by schelvis.cwi.nl with SMTP
  17444.     id AA28658 (5.65b/3.8/CWI-Amsterdam); Tue, 14 Sep 1993 10:32:49 +0200
  17445. Message-Id: <9309140832.AA28658=jack@schelvis.cwi.nl>
  17446. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  17447. Cc: python-list@cwi.nl
  17448. Subject: Re: My other pet python peeve - .sort(),.reverse(), etc. return None 
  17449. In-Reply-To: Message by "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> ,
  17450.          Mon, 13 Sep 1993 14:23:19 -0400 , <199309131823.AA13074@elvis.med.Virginia.EDU> 
  17451. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  17452. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  17453. X-Last-Band-Seen: Luka Bloom (Paradiso, 13-9)
  17454. X-Mini-Review: A grand way to start the weekend!
  17455. Date: Tue, 14 Sep 1993 10:32:48 +0200
  17456. From: Jack Jansen <Jack.Jansen@cwi.nl>
  17457.  
  17458.  
  17459. Recently, "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> said:
  17460. > ( And I can't even think of some likely + reasonable code that would
  17461. >  be broken by the change. I can't think that anyone ever *tests* 
  17462. >  that "list.sort() == None" - since that is, in fact, the only
  17463. >  possible return value. ) 
  17464. Well, if all my programs that use list.sort() suddenly start spouting
  17465. output all over the place, I would consider that "broken".
  17466. It wouldn't be the kind of thing that is difficult to find, though,
  17467. especially with the new -k flag.
  17468.  
  17469. There's another thing I don't like about this, though, and that is the
  17470. fact that you either have to make sort() only return the sorted list
  17471. (i.e. leave the original intact), or both return it and update it
  17472. in-place. The first option *does* have backward-compatability problems
  17473. (and is less efficient to boot, since the current sort only moves some
  17474. pointers around), and the second one is not very elegant.
  17475. --
  17476. Jack Jansen        | If I can't dance I don't want to be part of
  17477. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  17478. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  17479. 
  17480. 
  17481. Received: from mailgate.ericsson.se by charon.cwi.nl with SMTP
  17482.     id AA06681 (5.65b/3.10/CWI-Amsterdam); Wed, 15 Sep 1993 12:56:54 +0200
  17483. Received: from eua.ericsson.se by mailgate.ericsson.se (4.1/SMI-4.1-MAILGATE1.14)
  17484.     id AA06856; Wed, 15 Sep 93 12:54:00 +0200
  17485. Received: from ms.eua.ericsson.se by eua.ericsson.se (4.1/EUA-2.1)
  17486.     id AA08340; Wed, 15 Sep 93 12:53:57 +0200
  17487. Received: from euas09c18.eua.ericsson.se by ms.eua.ericsson.se (4.1/MS-2.1)
  17488.     id AA04976; Wed, 15 Sep 93 12:53:55 +0200
  17489. From: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  17490. Received: by euas09c18.eua.ericsson.se (4.1/client-1.3)
  17491.     id AA14092; Wed, 15 Sep 93 12:53:54 +0200
  17492. Date: Wed, 15 Sep 93 12:53:54 +0200
  17493. Message-Id: <9309151053.AA14092@euas09c18.eua.ericsson.se>
  17494. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  17495. Cc: Tim Peters <tim@ksr.com>, python-list@cwi.nl, sdm7g@virginia.edu
  17496. Subject: Re: My other pet python peeve - .sort(),.reverse(), etc. return None
  17497. In-Reply-To: <199309140708.AA11742@elvis.med.Virginia.EDU>
  17498. References: <199309140708.AA11742@elvis.med.Virginia.EDU>
  17499. Comments: Hyperbole mail buttons accepted, v3.07.
  17500.  
  17501. >>>>> Steven recently wrote:
  17502.  
  17503.   Steven> I don't think it bugs me THAT much, that I'ld become an
  17504.   Steven> island among python users. ( Any idea how many of us there
  17505.   Steven> are? )
  17506.  
  17507. Huh... There must be a few others on this list beside you guys. ;-)
  17508.  
  17509. Well I'm one but I usually only write a script or two the period of a
  17510. half year. So it is really hard to level with you on these types of
  17511. detailed discussion. But here goes anyway ...
  17512.  
  17513.   Steven> [ Although, I might be tempted to try it as an experiment,
  17514.   Steven> to see HOW many pieces of code the change might actually
  17515.   Steven> break, and how badly. ]
  17516.  
  17517. This is a conseptioal problem.
  17518.  
  17519. As I view (e.g what the gurus brainwashed me to think :-) the OO-world
  17520. is that it is convenient to think about two kinds or operations that
  17521. manipulate the objects, Procedures and Functions. Functions return
  17522. some value but does not change the object and with Procedures it is
  17523. the opposit. They do not return any value but do indeed manipulate the
  17524. objekt into a new state.
  17525.  
  17526. I don't know how stringent this is kept in python but at least I like
  17527. it. So the solution to Stevens problem would not be to change sort
  17528. into provide both services but rather to introduce another "function"
  17529. that would return the sorted value but would not change the
  17530. originating object.
  17531.  
  17532. %% Mats
  17533. 
  17534. 
  17535. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  17536.     id AA00500 (5.65b/3.10/CWI-Amsterdam); Thu, 16 Sep 1993 06:25:06 +0200
  17537. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa18355;
  17538.           16 Sep 93 0:25 EDT
  17539. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  17540.     id AA22362; Thu, 16 Sep 1993 00:24:53 -0400
  17541. Date: Thu, 16 Sep 1993 00:24:53 -0400
  17542. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  17543. Message-Id: <199309160424.AA22362@elvis.med.Virginia.EDU>
  17544. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  17545. To: python-list@cwi.nl
  17546. Subject: Stupid Python Tricks #2 
  17547.  
  17548.  
  17549.  
  17550. Re: pet peaves
  17551. Ok, Tim,Jack,Mats - 
  17552. I give up.
  17553. I guess I'm just a hopeless C-head! 
  17554. I will even admit, that after looking at the way the topic is 
  17555. introduced in the Tutorial, that it is also not as confusing or
  17556. arbitrary as I might have thought.
  17557.  
  17558. Re: exception and error handling 
  17559. And yes, Tim: Python is vastly better that Fortran, C, etc... 
  17560. It's just that I'm such a Python FAN that my expectations are
  17561. ALSO vastly higher. Also - I enjoy pushing at the edges and
  17562. finding out what I CAN'T do. What is FUN, is when you discover
  17563. that things are easier that you had thought.
  17564.  
  17565. Which brings me to "Stupic Python Trick #2" : 
  17566.  
  17567. I often find myself creating pieces of python code with this idiom:
  17568.  
  17569. list = []        # start with empty list and fill it
  17570. while Something :
  17571.     list.append( next_thing() )
  17572.  
  17573. -or- 
  17574.  
  17575. string = ''        # start with empty string and fill it
  17576. while Something:
  17577.     string = string + next_token() 
  17578.  
  17579. Sometime I find that I'm creating a what could be a generic 
  17580. function that operates on sequences, but I needed ( or at
  17581. least wanted ) the function to return the same type of 
  17582. sequence that it had been given. I couldn't figure out a 
  17583. good way to do this, other than checking the type of the
  17584. args and doing some conditional processing according to
  17585. the type. But, now, with the ability to create new classes
  17586. of sequences, that solution is even less satisfactory. 
  17587.  
  17588. Luckily, however, a description of one aspect of the
  17589. problem points to the solution.
  17590.  
  17591. Note the relation:
  17592. type( string )    == type( string[0] )
  17593. type( list )     <> type( list[0] )
  17594. type( tuple )    <> type( tuple[0] )
  17595.  
  17596. i.e.     Strings are composed of smaller strings, 
  17597.     But tuples and lists contain other things.
  17598.  
  17599. However, the relation that IS consistent is:
  17600.  
  17601. type( sequence ) == type( sequence[:0] ) 
  17602.  
  17603. i.e.  sequence[:0] is the empty sequence for all sequence types.
  17604.  
  17605. Which gives us the idion in the following example:
  17606. ( pace SICP, for the "iterative" recursive function. )
  17607.  
  17608. #!/usr/local/bin/python
  17609. #
  17610. def reverse( thing ):
  17611.     return revi( thing, thing[:0] )
  17612.  
  17613. def revi( a, b ):
  17614.     if not a : return b
  17615.     return revi( a[1:], a[:1]+b )
  17616.  
  17617. string = '123456789'
  17618. list = [ 1,2,3,4,5,6,7,8,9 ]
  17619. tuple = ( 1,2,3,4,5,6,7,8,9 )
  17620.  
  17621. string
  17622. reverse(string)
  17623. list
  17624. reverse(list)
  17625. tuple
  17626. reverse(tuple)
  17627.  
  17628.  
  17629. #-------------
  17630. which yields:
  17631.  
  17632. '123456789'
  17633. '987654321'
  17634. [1, 2, 3, 4, 5, 6, 7, 8, 9]
  17635. [9, 8, 7, 6, 5, 4, 3, 2, 1]
  17636. (1, 2, 3, 4, 5, 6, 7, 8, 9)
  17637. (9, 8, 7, 6, 5, 4, 3, 2, 1)
  17638.  
  17639. and should do the same for any user-written, sequence like class.
  17640.  
  17641.  I expect that this momentous discovery is actually burried somewhere
  17642. in the sources of one of Guido's demo scripts. Well - maybe if we 
  17643. trade some of these simple idioms, I can remind myself that python
  17644. is NOT  C,LISP,Pascal,ICON,Perl, or any other language, and stop
  17645. complaining about functions vs procedures, etc. Maybe we a creative
  17646. challenge to see how many different ways we can find to write a 
  17647. simple python program - sort of like the 4000 different ways to
  17648. print "Just another PERL hacker" that you always see in the sigs
  17649. on Comp.lang.perl. 
  17650.  
  17651. [ 'Hacker', 'Python', 'another', 'Just' ].reverse() 
  17652.  
  17653. !!! OOPS !!! - It didn't print anything!   - Steve 
  17654.  
  17655. 
  17656. 
  17657. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  17658.     id AA22217 (5.65b/3.10/CWI-Amsterdam); Thu, 16 Sep 1993 23:08:20 +0200
  17659. Received: by hermix.markv.com id ad09540; 16 Sep 93 14:06 PDT
  17660. To: python-list@cwi.nl
  17661. Subject: compile() builtin error catching..
  17662. X-Organization: Mark V Systems Ltd.
  17663. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  17664. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  17665. Date: Thu, 16 Sep 93 12:13:13 PDT
  17666. From: lance@markv.com
  17667. Sender: lance@markv.com
  17668. Message-Id:  <9309161213.aa06559@hermix.markv.com>
  17669. Source-Info:  From (or Sender) name not authenticated.
  17670.  
  17671.  
  17672. I have a program that loads text from an external file and passes
  17673. it to the builtin Python function compile(). I can put a try:except:
  17674. statement around it to catch when there ar sntax errors, etc.. BUT
  17675. I cannot get the LINE number that the error occured on. 
  17676. If I try to take a look at sys.exc_traceback.tb_lineno, it is garbage...
  17677.  
  17678. How can I get the line number from INSIDE a python program???
  17679. I could and MIGHT have to write this part in C, but would prefer NOT to
  17680. if at all possible..
  17681.  
  17682.  
  17683. --
  17684.  
  17685. Lance Ellinghouse           lance@markv.com
  17686.  
  17687. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  17688. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  17689. You can receive my Public Key by `finger lance@markv.com`
  17690. 
  17691. 
  17692. Received: from boulder.Colorado.EDU by charon.cwi.nl with SMTP
  17693.     id AA25704 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 00:04:25 +0200
  17694. Received: from vette.Colorado.EDU by boulder.Colorado.EDU with SMTP id AA03149
  17695.   (5.65c/IDA-1.4.4 for <@boulder.colorado.edu:python-list@cwi.nl>); Thu, 16 Sep 1993 16:04:20 -0600
  17696. Received: by vette.colorado.edu (920330.SGI/911001.SGI)
  17697.     for @boulder.colorado.edu:python-list@cwi.nl id AA04063; Thu, 16 Sep 93 16:04:18 -0600
  17698. Date: Thu, 16 Sep 93 16:04:18 -0600
  17699. From: michel@vette.colorado.edu (Michel Lesoinne)
  17700. Message-Id: <9309162204.AA04063@vette.colorado.edu>
  17701. To: python-list@cwi.nl
  17702. Subject: Python on Mac
  17703.  
  17704. I am trying to use python on a mac. I would like to know how I can run a
  17705. python program directly ? Is it possible to write a file that the Mac will
  17706. recognize as being a python script ? How can I compile my python script ?
  17707.  
  17708. Any help will be appreciated!
  17709.  
  17710. Michel
  17711. (michel@janus.colorado.edu)
  17712.  
  17713. 
  17714. 
  17715. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  17716.     id AA01086 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 00:38:49 +0200
  17717. To: python-list@cwi.nl
  17718. Subject: lineno on failed compile() commands...
  17719. X-Organization: Mark V Systems Ltd.
  17720. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  17721. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  17722. Date: Thu, 16 Sep 93 15:38:21 PDT
  17723. From: lance@markv.com
  17724. Sender: lance@markv.com
  17725. Message-Id:  <9309161538.aa22606@hermix.markv.com>
  17726. Source-Info:  From (or Sender) name not authenticated.
  17727.  
  17728.  
  17729. Well I looked around the code and saw that there was a way to 
  17730. extract the linenumber that the builtin.compile() command
  17731. was on when it fails.. But only from the C code and only
  17732. down inside the parser instead of the compiler...
  17733.  
  17734. I decided I would hack the code up a little so that if builtin.compile()
  17735. failed, it would create an attribute called sys.failed_lineno that could
  17736. be looked at that comtains JUST the line number. This is not the cleanest
  17737. but will allow me to continue...
  17738. I would use it like this:
  17739.  
  17740. try:
  17741.     co = compile(a,'<string>','exec')
  17742. except SyntaxError, msg:
  17743.     print 'SyntaxError: ' + msg + ' on line #' + `sys.lineno`
  17744.  
  17745. if anyone has a better idea or way to do it, please let me know...
  17746. Here are the diffs to allow this..
  17747. ===================================================================
  17748. RCS file: /u/lance/CVS/python/src/parsetok.c,v
  17749. retrieving revision 1.1.1.1
  17750. diff -c -r1.1.1.1 parsetok.c
  17751. *** 1.1.1.1    1993/09/09 20:58:43
  17752. --- parsetok.c    1993/09/16 20:19:17
  17753. ***************
  17754. *** 40,50 ****
  17755.   /* Parse input coming from a string.  Return error code, print some errors. */
  17756.   
  17757.   int
  17758. ! parsestring(s, g, start, n_ret)
  17759.       char *s;
  17760.       grammar *g;
  17761.       int start;
  17762.       node **n_ret;
  17763.   {
  17764.       struct tok_state *tok = tok_setups(s);
  17765.       int ret;
  17766. --- 40,51 ----
  17767.   /* Parse input coming from a string.  Return error code, print some errors. */
  17768.   
  17769.   int
  17770. ! parsestring(s, g, start, n_ret, lineno)
  17771.       char *s;
  17772.       grammar *g;
  17773.       int start;
  17774.       node **n_ret;
  17775. +         int *lineno;
  17776.   {
  17777.       struct tok_state *tok = tok_setups(s);
  17778.       int ret;
  17779. ***************
  17780. *** 54,59 ****
  17781. --- 55,65 ----
  17782.           return E_NOMEM;
  17783.       }
  17784.       ret = parsetok(tok, g, start, n_ret);
  17785. +     if (ret == E_TOKEN || ret == E_SYNTAX) {
  17786. +             if (lineno) {
  17787. +             *lineno = tok->lineno;
  17788. +         }
  17789. +     }
  17790.   /*
  17791.   XXX Need a more sophisticated way to report the line number.
  17792.       if (ret == E_TOKEN || ret == E_SYNTAX) {
  17793. ===================================================================
  17794. RCS file: /u/lance/CVS/python/src/parsetok.h,v
  17795. retrieving revision 1.1.1.1
  17796. diff -c -r1.1.1.1 parsetok.h
  17797. *** 1.1.1.1    1993/09/09 20:58:43
  17798. --- parsetok.h    1993/09/16 20:19:18
  17799. ***************
  17800. *** 30,36 ****
  17801.   
  17802.   /* Parser-tokenizer link interface */
  17803.   
  17804. ! extern int parsestring PROTO((char *, grammar *, int start, node **n_ret));
  17805.   extern int parsefile PROTO((FILE *, char *, grammar *, int start,
  17806.                       char *ps1, char *ps2, node **n_ret));
  17807.   
  17808. --- 30,36 ----
  17809.   
  17810.   /* Parser-tokenizer link interface */
  17811.   
  17812. ! extern int parsestring PROTO((char *, grammar *, int start, node **n_ret, int *lineno));
  17813.   extern int parsefile PROTO((FILE *, char *, grammar *, int start,
  17814.                       char *ps1, char *ps2, node **n_ret));
  17815.   
  17816. ===================================================================
  17817. RCS file: /u/lance/CVS/python/src/pythonrun.c,v
  17818. retrieving revision 1.1.1.1
  17819. diff -c -r1.1.1.1 pythonrun.c
  17820. *** 1.1.1.1    1993/09/09 20:57:38
  17821. --- pythonrun.c    1993/09/16 22:10:05
  17822. ***************
  17823. *** 267,273 ****
  17824.   {
  17825.       node *n;
  17826.       int err;
  17827. !     err = parse_string(str, start, &n);
  17828.       return run_err_node(err, n, "<string>", globals, locals);
  17829.   }
  17830.   
  17831. --- 267,273 ----
  17832.   {
  17833.       node *n;
  17834.       int err;
  17835. !     err = parse_string(str, start, &n, 0);
  17836.       return run_err_node(err, n, "<string>", globals, locals);
  17837.   }
  17838.   
  17839. ***************
  17840. *** 334,342 ****
  17841.       node *n;
  17842.       int err;
  17843.       codeobject *co;
  17844. !     err = parse_string(str, start, &n);
  17845.       if (err != E_DONE) {
  17846.           err_input(err);
  17847.           return NULL;
  17848.       }
  17849.       co = compile(n, filename);
  17850. --- 334,347 ----
  17851.       node *n;
  17852.       int err;
  17853.       codeobject *co;
  17854. !     int lineno; /* If error, this holds line number of failure */
  17855. !     /* make sure "failed_lineno" does not exist incase things work ok */
  17856. !     sysset("failed_lineno",NULL);
  17857. !     err = parse_string(str, start, &n, &lineno);
  17858.       if (err != E_DONE) {
  17859.           err_input(err);
  17860. +         /* Set "failed_lineno" so you can capture line of failure */
  17861. +         sysset("failed_lineno",newintobject(lineno));
  17862.           return NULL;
  17863.       }
  17864.       co = compile(n, filename);
  17865. ***************
  17866. *** 364,375 ****
  17867.   /* Simplified interface to parsestring */
  17868.   
  17869.   int
  17870. ! parse_string(str, start, n_ret)
  17871.       char *str;
  17872.       int start;
  17873.       node **n_ret;
  17874.   {
  17875. !     int err = parsestring(str, &gram, start, n_ret);
  17876.       /* Don't confuse early end of string with early end of input */
  17877.       if (err == E_EOF)
  17878.           err = E_SYNTAX;
  17879. --- 369,381 ----
  17880.   /* Simplified interface to parsestring */
  17881.   
  17882.   int
  17883. ! parse_string(str, start, n_ret, lineno)
  17884.       char *str;
  17885.       int start;
  17886.       node **n_ret;
  17887. +         int *lineno;
  17888.   {
  17889. !     int err = parsestring(str, &gram, start, n_ret, lineno);
  17890.       /* Don't confuse early end of string with early end of input */
  17891.       if (err == E_EOF)
  17892.           err = E_SYNTAX;
  17893. ===================================================================
  17894. RCS file: /u/lance/CVS/python/src/pythonrun.h,v
  17895. retrieving revision 1.1.1.1
  17896. diff -c -r1.1.1.1 pythonrun.h
  17897. *** 1.1.1.1    1993/09/09 20:58:42
  17898. --- pythonrun.h    1993/09/16 20:19:19
  17899. ***************
  17900. *** 39,45 ****
  17901.   int run_tty_1 PROTO((FILE *, char *));
  17902.   int run_tty_loop PROTO((FILE *, char *));
  17903.   
  17904. ! int parse_string PROTO((char *, int, struct _node **));
  17905.   int parse_file PROTO((FILE *, char *, int, struct _node **));
  17906.   
  17907.   object *eval_node PROTO((struct _node *, char *, object *, object *));
  17908. --- 39,45 ----
  17909.   int run_tty_1 PROTO((FILE *, char *));
  17910.   int run_tty_loop PROTO((FILE *, char *));
  17911.   
  17912. ! int parse_string PROTO((char *, int, struct _node **, int *));
  17913.   int parse_file PROTO((FILE *, char *, int, struct _node **));
  17914.   
  17915.   object *eval_node PROTO((struct _node *, char *, object *, object *));
  17916.  
  17917. --
  17918.  
  17919. Lance Ellinghouse           lance@markv.com
  17920.  
  17921. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  17922. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  17923. You can receive my Public Key by `finger lance@markv.com`
  17924. 
  17925. 
  17926. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  17927.     id AA14514 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 04:08:33 +0200
  17928. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  17929.     id AA05446; Thu, 16 Sep 1993 22:08:33 -0400
  17930. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  17931.     id AA10473; Thu, 16 Sep 93 22:08:28 EDT
  17932. Received: by kaos.ksr.com (4.1/KSR-2.0)
  17933.     id AA15722; Thu, 16 Sep 93 22:08:19 EDT
  17934. Message-Id: <9309170208.AA15722@kaos.ksr.com>
  17935. To: sdm7g@virginia.edu, python-list@cwi.nl
  17936. Subject: Re: Stupid Python Tricks #2
  17937. Date: Thu, 16 Sep 93 22:08:18 -0400
  17938. From: Tim Peters <tim@ksr.com>
  17939.  
  17940. "Python tricks" is a tough one, cuz the language is so clean.  E.g., C
  17941. makes an art of confusing pointers with arrays and strings, which leads
  17942. to lotsa neat pointer tricks; APL mistakes everything for an array,
  17943. leading to neat one-liners; and Perl confuses everything period, making
  17944. each line a joyous adventure <wink>.
  17945.  
  17946. I've seen Python criticized as "ugly" precisely because it _doesn't_ have
  17947. a trick-based view of the world.  In many ways, it's a dull language,
  17948. borrowing solid old concepts from many other languages & styles:  boring
  17949. syntax, unsurprising semantics, few automatic coercions, etc etc.  But
  17950. that's one of the things I like about it.
  17951.  
  17952. The trickiest areas in my experience have to do with namespace
  17953. management, both the cool way classes introduce dynamic new namespaces,
  17954. and the way assignment in general merely binds a name to an object.  You
  17955. can do some very powerful things after grasping these, but they're
  17956. already illustrated well in the distributed Python samples.
  17957.  
  17958. The most practical-- but mundane --"trick" I've stumbled into is a speed
  17959. trick, when using a dict to accumulate info, and accesses to existing
  17960. keys outnumber new keys.  E.g.,
  17961.  
  17962.    try: dict[key] = dict[key] + 1
  17963.    except KeyError: dict[key] = 0
  17964.  
  17965. can run a good deal faster than
  17966.  
  17967.    if dict.has_key(key):
  17968.       dict[key] = dict[key] + 1
  17969.    else:
  17970.       dict[key] = 0
  17971.  
  17972. I imagine that's because the latter looks up the key 3 times, instead of
  17973. twice in the former, in the usual (the key is usually present, by
  17974. supposition) case.
  17975.  
  17976. But then putting a little smarts into the translator would allow either
  17977. form to map into runtime code that did only 1 key lookup.  What I'd
  17978. _really_ like to write is (a la C, Icon, Perl, etc)
  17979.  
  17980.    try: dict[key] += 1  # hypothetical augmented assignment operator '+='
  17981.    except KeyError: dict[key] = 0
  17982.  
  17983. I.e., to be able to write it in a way that a mindless translator would
  17984. usually map to a single key lookup.
  17985.  
  17986. > ...
  17987. > challenge to see how many different ways we can find to write a
  17988. > simple python program - sort of like the 4000 different ways to
  17989. > print "Just another PERL hacker" that you always see in the sigs
  17990. > on Comp.lang.perl.
  17991.  
  17992. Hey, I'm game <grin>!  Here's another way to write reverse:
  17993.  
  17994. def rev( x ):
  17995.     l2 = len(x)/2
  17996.     if l2:
  17997.     return rev(x[l2:]) + rev(x[:l2])
  17998.     else:
  17999.     return x
  18000.  
  18001. It works for strings/tuples/lists/user_sequences, and has the practical
  18002. advantage that the call stack doesn't grow deeper than log2(len(x)).
  18003.  
  18004. >>> rev((rev('rekcah'),rev('nohtyP'),rev('rehtona'),rev('tsuJ')))
  18005. ('Just', 'another', 'Python', 'hacker')
  18006. >>>
  18007.  
  18008. even-obfuscated-python's-darned-easy-to-read-ly y'rs  - tim
  18009.  
  18010. Tim Peters   tim@ksr.com
  18011. not speaking for Kendall Square Research Corp
  18012. 
  18013. 
  18014. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  18015.     id AA18792 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 16:44:48 +0200
  18016. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa14392;
  18017.           17 Sep 93 10:43 EDT
  18018. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  18019.     id AA19247; Fri, 17 Sep 1993 10:15:58 -0400
  18020. Date: Fri, 17 Sep 1993 10:15:58 -0400
  18021. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  18022. Message-Id: <199309171415.AA19247@elvis.med.Virginia.EDU>
  18023. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  18024. To: Michel Lesoinne <michel@vette.colorado.edu>
  18025. Subject: Re: Python on Mac
  18026. Cc: python-list@cwi.nl
  18027.  
  18028. Well - I haven't used the Mac Python for a while so I'm not sure, 
  18029. but generally, Mac documents have a TYPE field and a CREATOR field. 
  18030. If you write a python script with an Mac editor, the TYPE field will
  18031. be set to 'TEXT' ( assuming you save it AS text, and not some native
  18032. format ) and the CREATOR will be the Editor program. The creator field
  18033. is used to tell the system what program to launch when the document is
  18034. clicked on. So if you change the creator field to the field for Python
  18035. ( does anyone happen to know what that is? ) then the system will launch
  18036. python when you click on that file. It is then up to the application 
  18037. ( PYTHON ) to recognize that it has been given an initial event ( a
  18038. file open event ) and open and read that file. I don't happen to know 
  18039. if Mac Python does this.  If I get a chance to sit in front of a Mac 
  18040. for a while, I'll give it a test. 
  18041.  
  18042.  Does Mac Python generate .pyc files ? and are they set to
  18043. creator=Python ? If that is the case, then the .pyc files should be 
  18044. 'clickable' applications. 
  18045.  
  18046.  
  18047. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  18048. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  18049.  
  18050. 
  18051. 
  18052. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  18053.     id AA01309 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 18:43:46 +0200
  18054. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa29145;
  18055.           17 Sep 93 12:43 EDT
  18056. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  18057.     id AA22013; Fri, 17 Sep 1993 12:30:49 -0400
  18058. Date: Fri, 17 Sep 1993 12:30:49 -0400
  18059. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  18060. Message-Id: <199309171630.AA22013@elvis.med.Virginia.EDU>
  18061. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  18062. To: Tim Peters <tim@ksr.com>, sdm7g@virginia.edu, python-list@cwi.nl
  18063. Subject: Re: Stupid Python Tricks #2
  18064.  
  18065. On Sep 16, 22:08, Tim Peters wrote:
  18066. > "Python tricks" is a tough one, cuz the language is so clean.  E.g., C
  18067. > makes an art of confusing pointers with arrays and strings, which leads
  18068. > to lotsa neat pointer tricks; APL mistakes everything for an array,
  18069. > leading to neat one-liners; and Perl confuses everything period, making
  18070. > each line a joyous adventure <wink>.
  18071.  
  18072. I agree, Tim. Clearly, my 'Obfuscated Python' subject line was meant
  18073. tongue in cheek - as in, "this is about as obfuscated as I can get
  18074. in python". Well - not quite, since you managed to top me with:
  18075.  
  18076. [ from an earlier email message: ]
  18077. > while exec('x=stdin.readline()') or (x and (stdout.write(process(x)) or x)):
  18078. >     pass
  18079. > is clearly the _correct_ way to do it <grin>.
  18080. >
  18081.  
  18082.  
  18083. > I've seen Python criticized as "ugly" precisely because it _doesn't_ have
  18084. > a trick-based view of the world.  In many ways, it's a dull language,
  18085. > borrowing solid old concepts from many other languages & styles:  boring
  18086. > syntax, unsurprising semantics, few automatic coercions, etc etc.  But
  18087. > that's one of the things I like about it.
  18088. > The trickiest areas in my experience have to do with namespace
  18089. > management, both the cool way classes introduce dynamic new namespaces,
  18090. > and the way assignment in general merely binds a name to an object.  You
  18091. > can do some very powerful things after grasping these, but they're
  18092. > already illustrated well in the distributed Python samples.
  18093.  
  18094. Well - sometimes there are "suprising semantics" introduced by the
  18095. namespace management.(*) So if we TRULY want to write some obfuscated
  18096. python, it should clearly do something subtle with the name space, 
  18097. or tricky 'eval' or 'compiles' of generated strings, or Classes that
  18098. define non-intuitive meanings for '+' or '[i]' .  So, yes, you CAN
  18099. write _REALLY_ obfuscated python, but you have to go quite out of
  18100. your way to make the effort. ( As opposed to 'C', where you have to
  18101. go quite out of your way to un-obfuscate it! ) 
  18102.  
  18103. [ (*) Recall the confusion I had long ago with module global names - 
  18104.  it has since been "fixed" with 'global' and a couple of other
  18105.  changes,  but it was, I recall a very subtle and interesting side
  18106.  effect of the python namespace. ] 
  18107.  
  18108. > even-obfuscated-python's-darned-easy-to-read-ly y'rs  - tim
  18109.  
  18110.  
  18111. But I wouldn't describe python as "dull" ! 
  18112. One of the things that makes it interesting, is exactly how
  18113. much Guido has managed to exploit that *one* implementation trick
  18114. of 'namespaces'.  Python is built around the concept of 
  18115. namespace - just as arrays are at the core of APL and lists/S-expr's
  18116. are the secret of the power of LISP. And as a result, I think it
  18117. makes it a quite comprehensible language. I don't often have time
  18118. to read thru the python sources, but I still feel I have a sort-of-basic
  18119. understanding of how things work "under-the-hood" . 
  18120.  
  18121. FORTH and LISP both have a very simple, comprehensible core language 
  18122. upon which a much more elaborate system is constructed. FORTH is 
  18123. built around threaded-code and dictionaries ( which, unsuprisingly,
  18124. can be made to do some similar things as python's namespaces - there
  18125. are FORTH words which change the dictionary search order, and thus 
  18126. the context for evaluation of following words. ) Lisp is built upon
  18127. lists and the read-eval-print of S-expressions. 
  18128.  
  18129. Python is a bit more complicated, but much of that complication is 
  18130. just (as they say) "surface syntax". In python - everything is an
  18131. object, and a name is turned into an object via dictionary lookup
  18132. in the namespace of the current context. Modules and classes both
  18133. create new namespaces, and reference to a module or a class instance
  18134. changes the evaluation context. 
  18135.  
  18136. This simplicity counts for a lot when you DO need to extend or 
  18137. embed the interpreter. We have seen a number of posts to this 
  18138. list about 'I changed python to do this...' ( the most recent 
  18139. being Lance's addition of line number error tracing to 'compile()' )
  18140.  
  18141. The idea of adding a new data type to python doesn't scare me. 
  18142. ( The only thing I thought I might actually need was arrays, 
  18143.  to make more effecient passing to and from a C program that 
  18144.  would have an embedded python interpreter - but someone else 
  18145.  has already done that - Thanks guys! ) 
  18146.  
  18147.  
  18148. Some of this is due to the level of documentation that Guido 
  18149. has supplied, but a lot of it is due to starting with a clean 
  18150. design and a simple concept. 
  18151.  
  18152.  
  18153. I have never looked "under-the-hood" at perl in nearly as much
  18154. detail - the surface frightened me off!  
  18155.  
  18156.  
  18157.  
  18158. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  18159. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  18160.  
  18161. 
  18162. 
  18163. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  18164.     id AA03818 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 20:27:13 +0200
  18165. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa01285;
  18166.           17 Sep 93 12:56 EDT
  18167. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  18168.     id AA19994; Fri, 17 Sep 1993 12:56:38 -0400
  18169. Date: Fri, 17 Sep 1993 12:56:38 -0400
  18170. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  18171. Message-Id: <199309171656.AA19994@elvis.med.Virginia.EDU>
  18172. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  18173. To: Tim Peters <tim@ksr.com>, sdm7g@virginia.edu, python-list@cwi.nl
  18174. Subject: Other tricks with dictionaries ( was Stupid Python Trick #2 )
  18175.  
  18176.  
  18177. I pretty much ignored the discussion that followed the proposal that
  18178. dictionary mappings be extended to have keys other that type string. 
  18179.  
  18180. I really didn't see a need for them myself ( at the time ) - you could
  18181. always use `thing` as the key string. 
  18182.  
  18183. But now that they ARE arbitrarily indexable - I have discovered that
  18184. the REALLY neat thing is that dictionaries are now INVERTABLE. 
  18185.  
  18186. This is sometimes and easy solution to an awkward problem. 
  18187.  
  18188. Please excuse me if this was the obvious point of the whole proposal. 
  18189. I may have been too dense at the time to figure that out, but it 
  18190. now looks like such an obvious trick now, that I have even used it
  18191. when it wasn't necessary: i.e. the special case where I was mapping
  18192. from strings to integers, could be reverse mapped with a list of 
  18193. strings where  list.index( 'string' ) == dict['string']. The more 
  18194. general solution of building an inverse dictionary may have much 
  18195. wider uses. 
  18196.  
  18197.  
  18198. -Steve Majewski             (804-982-0831)              <sdm7g@Virginia.EDU>
  18199. -Univ. of Virginia Department of Molecular Physiology and Biological Physics
  18200.  
  18201.  
  18202. 
  18203. 
  18204. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  18205.     id AA03682 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 20:22:24 +0200
  18206. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa13657;
  18207.           17 Sep 93 14:22 EDT
  18208. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  18209.     id AA23257; Fri, 17 Sep 1993 14:22:14 -0400
  18210. Date: Fri, 17 Sep 1993 14:22:14 -0400
  18211. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  18212. Message-Id: <199309171822.AA23257@elvis.med.Virginia.EDU>
  18213. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  18214. To: Tim Peters <tim@ksr.com>, sdm7g@virginia.edu, python-list@cwi.nl
  18215. Subject: virtues and simplicity of python ( was: Stupid Python Tricks #2 ) 
  18216.  
  18217.  
  18218. But I'm sure I'm just preaching to the converted here!
  18219. Maybe I should post that to comp.lang.misc or someplace. 
  18220. The list is nice because we avoid all of the language wars 
  18221. and flames, but I think we DO need to do a bit of advertising 
  18222. once and a while. - Steve M. 
  18223.  
  18224. 
  18225. 
  18226. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  18227.     id AA06309 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 22:43:10 +0200
  18228. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa01518;
  18229.           17 Sep 93 16:43 EDT
  18230. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  18231.     id AA13194; Fri, 17 Sep 1993 16:43:01 -0400
  18232. Date: Fri, 17 Sep 1993 16:43:01 -0400
  18233. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  18234. Message-Id: <199309172043.AA13194@elvis.med.Virginia.EDU>
  18235. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  18236. To: python-list@cwi.nl
  18237. Subject: My other pet python peeve - .sort(),.reverse(), etc. return None
  18238.  
  18239.  
  18240. Silly me! My "Silly Python Trick #2" provides the obvious solution
  18241. to the general problem of wanting a procedure that also return an 
  18242. updated object: 
  18243.  
  18244.   ( thing.procedural_method() or thing ) ==> updated thing
  18245.  
  18246. as in:
  18247.  
  18248. >>> b = []
  18249. >>> for c in 'aBcDeFg' : Z = ( b.append(c) or b.reverse() or b ) 
  18250. ... else: Z
  18251. ... 
  18252. ['g', 'e', 'c', 'a', 'B', 'D', 'F']
  18253. >>> 
  18254.  
  18255.  
  18256. BTW: The parends are necessary for: ( 1 or 2 )
  18257.  
  18258. >>> 1 or 2
  18259. Parsing error: file <stdin>, line 1:
  18260. 1 or 2
  18261.     ^
  18262. SyntaxError: invalid syntax
  18263. >>> ( 1 or 2 )
  18264. 1
  18265.  
  18266. Is this just an residue of the days when the parser had 
  18267. to distinguish between boolean and binding "=", or does 
  18268. it fulfill some other syntactical need ?
  18269.  
  18270. - Steve M.
  18271.  
  18272. 
  18273. 
  18274. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  18275.     id AA06522 (5.65b/3.10/CWI-Amsterdam); Fri, 17 Sep 1993 23:33:38 +0200
  18276. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa09534;
  18277.           17 Sep 93 17:33 EDT
  18278. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  18279.     id AA21517; Fri, 17 Sep 1993 17:33:24 -0400
  18280. Date: Fri, 17 Sep 1993 17:33:24 -0400
  18281. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  18282. Message-Id: <199309172133.AA21517@elvis.med.Virginia.EDU>
  18283. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  18284. To: python-list@cwi.nl
  18285. Subject: obfuscated python
  18286.  
  18287. Of course, in the intentional obfuscation category,
  18288. there is always:
  18289.  
  18290. >>> a = range( 1, 11 )
  18291. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  18292.  
  18293. >>> ( eval( 'a.'+[].__methods__[-2] )()  or a )
  18294.  
  18295. # ( take a guess ... )
  18296.  
  18297.  
  18298. [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
  18299.  
  18300.  
  18301. or maybe:
  18302.  
  18303. >>> import sys
  18304. >>> eval( eval( 'dir()[-1]', sys.__dict__ ), sys.__dict__ ) 
  18305.  
  18306.  
  18307.  
  18308.  
  18309. '0.9.9 (Sep  7 1993)'
  18310.  
  18311.  
  18312. And numerous other ways to avoid actually naming the act!
  18313.  
  18314. - Steve M.
  18315.  
  18316. 
  18317. 
  18318. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  18319.     id AA10815 (5.65b/3.10/CWI-Amsterdam); Sat, 18 Sep 1993 00:25:11 +0200
  18320. To: python-list@cwi.nl
  18321. Subject: FTP site for Python scripts
  18322. X-Organization: Mark V Systems Ltd.
  18323. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  18324. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  18325. Date: Fri, 17 Sep 93 15:23:36 PDT
  18326. From: lance@markv.com
  18327. Sender: lance@markv.com
  18328. Message-Id:  <9309171523.aa03097@hermix.markv.com>
  18329. Source-Info:  From (or Sender) name not authenticated.
  18330.  
  18331.  
  18332. I have created 2 directories on our FTP site for people to 
  18333. place Python script files as well as get any that people place there..
  18334.  
  18335. The site is: ftp.markv.com (192.122.251.1)
  18336. The place to put them is in /incoming/python
  18337. The place they will be put for general usage is /pub/python
  18338.  
  18339. The /incoming/python directory is a drop directory.. you cannot
  18340. do a directory listing of it..
  18341.  
  18342. If you place any files in there, please either upload a file.readme
  18343. file to explain what the file(s) do and I will place that description
  18344. along with the actual files.. I will also maintain a file that contains
  18345. a short description as well as who uploaded it (if that info is in the
  18346. readme file or Emailed)...
  18347.  
  18348. Currently I don't know of any FTP site that is acting as a repository
  18349. of script files for python besides Guido's. Let's start exchanging
  18350. ideas and code.. I will be placing a couple modules I have into these
  18351. directories for a starting place to build from..
  18352.  
  18353. If there is enough interest and enough is posted to this location,
  18354. I will also post to this mailing list the summary file every now and then.
  18355.  
  18356.  
  18357. --
  18358.  
  18359. Lance Ellinghouse           lance@markv.com
  18360.  
  18361. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  18362. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  18363. You can receive my Public Key by `finger lance@markv.com`
  18364. 
  18365. 
  18366. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  18367.     id AA02744 (5.65b/3.10/CWI-Amsterdam); Sun, 19 Sep 1993 06:42:11 +0200
  18368. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  18369.     id AA08615; Sun, 19 Sep 1993 00:40:54 -0400
  18370. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  18371.     id AA25771; Sun, 19 Sep 93 00:42:15 EDT
  18372. Received: by kaos.ksr.com (4.1/KSR-2.0)
  18373.     id AA15213; Sun, 19 Sep 93 00:42:12 EDT
  18374. Message-Id: <9309190442.AA15213@kaos.ksr.com>
  18375. To: sdm7g@virginia.edu, python-list@cwi.nl
  18376. Subject: Re: obfuscated python
  18377. Date: Sun, 19 Sep 93 00:42:12 -0400
  18378. From: Tim Peters <tim@ksr.com>
  18379.  
  18380. > >>> b = []
  18381. > >>> for c in 'aBcDeFg' : Z = ( b.append(c) or b.reverse() or b )
  18382. > ... else: Z
  18383.  
  18384. > >>> ( eval( 'a.'+[].__methods__[-2] )()  or a )
  18385.  
  18386. > >>> import sys
  18387. > >>> eval( eval( 'dir()[-1]', sys.__dict__ ), sys.__dict__ )
  18388.  
  18389. Oh, bletch!  Those are disgusting, Steve.  I can't compete at this level
  18390. of perversity, but I do encourage you to keep up the delightfully
  18391. revolting work <smile>.
  18392.  
  18393. > >>> 1 or 2
  18394. > Parsing error: file <stdin>, line 1:
  18395. > 1 or 2
  18396. >     ^
  18397. > SyntaxError: invalid syntax
  18398. > >>> ( 1 or 2 )
  18399. > 1
  18400. >
  18401. > Is this just an residue of the days when the parser had
  18402. > to distinguish between boolean and binding "=", or does
  18403. > it fulfill some other syntactical need ?
  18404.  
  18405. These behaviors still follow from the formal syntax in the reference
  18406. manual, but I'm not sure they _need_ to anymore (I too recall them
  18407. stemming from the need to disambiguate a=b=c back in the days when "="
  18408. was the both the equality and the assignment operator).
  18409.  
  18410. I often get burned by this variation too:
  18411.  
  18412.   for i in 1,2,3:
  18413.  
  18414. is legit, but
  18415.  
  18416.   if i in 1,2,3:
  18417.  
  18418. is a syntax error (needs to be
  18419.  
  18420.   if i in (1,2,3):
  18421.  
  18422. or a moral equivalent instead).
  18423.  
  18424. And the following is a very subtle oops-you-really-wanted-a-tuple there
  18425. mistake (subtle because it's not a syntax error):
  18426.  
  18427. try:
  18428.     some_code()
  18429. except ZeroDivisionError, NameError:
  18430.     pass
  18431.  
  18432. I.e., if some_code() does raise ZeroDivisionError, the name NameError
  18433. gets bound to 'integer division or modulo' (the "detail" of the
  18434. ZeroDivisionError), and so any subsequent attempt to catch NameError will
  18435. fail.
  18436.  
  18437. It took an awful long time to figure out what went wrong when (something
  18438. similar to) this bit me in a real program.  But I don't complain, because
  18439. it broke me of the bad habit of relying on catching exceptions <0.9 grin>.
  18440.  
  18441. thank-god-i-still-smoke-ly y'rs  - tim, grateful for one vice
  18442.  
  18443. Tim Peters   tim@ksr.com
  18444. not speaking for Kendall Square Research Corp
  18445. 
  18446. 
  18447. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  18448.     id AA05053 (5.65b/3.10/CWI-Amsterdam); Sun, 19 Sep 1993 07:29:56 +0200
  18449. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  18450.     id AA08653; Sun, 19 Sep 1993 01:28:34 -0400
  18451. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  18452.     id AA26124; Sun, 19 Sep 93 01:29:54 EDT
  18453. Received: by kaos.ksr.com (4.1/KSR-2.0)
  18454.     id AA15356; Sun, 19 Sep 93 01:29:50 EDT
  18455. Message-Id: <9309190529.AA15356@kaos.ksr.com>
  18456. To: sdm7g@virginia.edu, python-list@cwi.nl
  18457. Subject: Re: Other tricks with dictionaries
  18458. Date: Sun, 19 Sep 93 01:29:50 -0400
  18459. From: Tim Peters <tim@ksr.com>
  18460.  
  18461. Ya, invertibility is good stuff!  There are a couple other reasons for
  18462. wanting general keys:
  18463.  
  18464. 1) Possibility.  Python can't build a string representation for a
  18465.    structure with loops, so the `make_key_a_string` idiom didn't always
  18466.    work.  Along with the new id() function, dicts can now (with a little
  18467.    care) be indexed by anything.
  18468.  
  18469. 2) Efficiency.  Computing a string representation can be arbitrarily
  18470.    expensive.  E.g., consider a class instance that carries a lot of
  18471.    state.  Or just long integers (`longint` takes time quadratic in the
  18472.    length of the string).
  18473.  
  18474. 3) Convenience.  E.g., needing to backquote integer keys was an
  18475.    irritation.
  18476.  
  18477. > The more general solution of building an inverse dictionary may have
  18478. > much wider uses.
  18479.  
  18480. A random one came up the other day, while prototyping a register
  18481. assigner:
  18482.  
  18483. 1) Given such & such a register, which expression does it currently
  18484.    contain?
  18485.  
  18486. 2) Given a specific expression, in which register(s) can it currently be
  18487.    found?
  18488.  
  18489. Of course there are _lots_ of mappings that are interesting in both
  18490. directions, and a pair of "mirror" dicts is a pleasant way to deal with
  18491. 'em.
  18492.  
  18493. happily y'rs  - tim
  18494.  
  18495. Tim Peters   tim@ksr.com
  18496. not speaking for Kendall Square Research Corp
  18497. 
  18498. 
  18499. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  18500.     id AA07895 (5.65b/3.10/CWI-Amsterdam); Mon, 20 Sep 1993 22:10:09 +0200
  18501. From: Lance Ellinghouse <lance@markv.com>
  18502. X-Mailer: SCO System V Mail (version 3.2)
  18503. To: python-list@cwi.nl
  18504. Subject: classes or scripts for FTP site??
  18505. Date: Mon, 20 Sep 93 13:09:24 PDT
  18506. Message-Id:  <9309201309.aa12858@hermix.markv.com>
  18507.  
  18508. Does anyone have any classes or scripts that can be placed on the FTP site?
  18509. How about new C code modules?
  18510.  
  18511. Lance Ellinghouse
  18512. lance@markv.com
  18513. 
  18514. 
  18515. Replied: Wed, 22 Sep 1993 23:37:54 +0200
  18516. Replied: lance@markv.com
  18517. Replied: python-list@cwi.nl
  18518. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  18519.     id AA17131 (5.65b/3.10/CWI-Amsterdam); Wed, 22 Sep 1993 23:03:31 +0200
  18520. To: python-list@cwi.nl
  18521. Subject: TERMIO.py ???
  18522. X-Organization: Mark V Systems Ltd.
  18523. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  18524. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  18525. Date: Wed, 22 Sep 93 14:02:19 PDT
  18526. From: lance@markv.com
  18527. Sender: lance@markv.com
  18528. Message-Id:  <9309221402.aa26578@hermix.markv.com>
  18529. Source-Info:  From (or Sender) name not authenticated.
  18530.  
  18531. hello...
  18532.  
  18533. I cannot seem to find TERMIO.py anywhere.. Where can I get it? 
  18534. any pointers??
  18535.  
  18536. Thanks
  18537. --
  18538.  
  18539. Lance Ellinghouse           lance@markv.com
  18540.  
  18541. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  18542. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  18543. You can receive my Public Key by `finger lance@markv.com`
  18544. 
  18545. 
  18546. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  18547.     id AA17385 (5.65b/3.10/CWI-Amsterdam); Wed, 22 Sep 1993 23:36:38 +0200
  18548. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  18549.     id AA07043; Wed, 22 Sep 93 14:37:07 -0700
  18550. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  18551.     id AA29206; Wed, 22 Sep 93 14:39:23 -0700
  18552. Received: by ushqgw.sequent.com with Microsoft Mail
  18553.     id <2CA0C4A3@ushqgw.sequent.com>; Wed, 22 Sep 93 14:33:23 PDT
  18554. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  18555. To: lance <lance@markv.com>, python-list <python-list@cwi.nl>
  18556. Subject: RE: TERMIO.py ???
  18557. Date: Wed, 22 Sep 93 14:31:00 PDT
  18558. Message-Id: <2CA0C4A3@ushqgw.sequent.com>
  18559. Encoding: 15 TEXT
  18560. X-Mailer: Microsoft Mail V3.0
  18561.  
  18562.  
  18563. | I cannot seem to find TERMIO.py anywhere.. Where can I get it?
  18564. | any pointers??
  18565.  
  18566. I just made one from scratch, since these kinds of files may be system 
  18567. specific. Guido wrote a little script in one of the demo directories 
  18568. (something like h2py) to process a header file and turn it into a python 
  18569. module. Although not complete, it mostly does the job, with some manual 
  18570. edits afterwards. In general, if Python is going to provide lower level 
  18571. functionality such as fcntl and ioctl (which I argued for and like very 
  18572. much), it should also provide some fully functional header rewriting script, 
  18573. like Perl. At least twice I started writing a script like that but never 
  18574. finished. :-)
  18575.  
  18576.      -Jaap-
  18577. 
  18578. 
  18579. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  18580.     id AA17403 (5.65b/3.10/CWI-Amsterdam); Wed, 22 Sep 1993 23:37:53 +0200
  18581. Received: by voorn.cwi.nl with SMTP
  18582.     id AA09374 (5.65b/3.8/CWI-Amsterdam); Wed, 22 Sep 1993 23:37:53 +0200
  18583. Message-Id: <9309222137.AA09374=guido@voorn.cwi.nl>
  18584. To: lance@markv.com
  18585. Cc: python-list@cwi.nl
  18586. Subject: Re: TERMIO.py ??? 
  18587. In-Reply-To: Your message of "Wed, 22 Sep 1993 14:02:19 MDT."
  18588.              <9309221402.aa26578@hermix.markv.com> 
  18589. From: Guido.van.Rossum@cwi.nl
  18590. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  18591. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  18592. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  18593. Date: Wed, 22 Sep 1993 23:37:52 +0200
  18594. Sender: Guido.van.Rossum@cwi.nl
  18595.  
  18596. Hmm, can't find it either.  But I can't remember where it's being used
  18597. either.  It's probably the result of running <termio.h> through the
  18598. h2py.py script (demo/scripts), possibly followed by a little manual
  18599. fiddling...
  18600. --Guido
  18601. 
  18602. 
  18603. Replied: Fri, 24 Sep 1993 11:48:23 +0200
  18604. Replied: "michel@vette.colorado.edu (Michel Lesoinne) python-list@cwi.nl"
  18605. Received: from boulder.Colorado.EDU by charon.cwi.nl with SMTP
  18606.     id AA13587 (5.65b/3.10/CWI-Amsterdam); Thu, 23 Sep 1993 22:09:18 +0200
  18607. Received: from vette.Colorado.EDU by boulder.Colorado.EDU with SMTP id AA27891
  18608.   (5.65c/IDA-1.4.4 for <@boulder.colorado.edu:python-list@cwi.nl>); Thu, 23 Sep 1993 14:09:03 -0600
  18609. Received: by vette.colorado.edu (920330.SGI/911001.SGI)
  18610.     for @boulder.colorado.edu:python-list@cwi.nl id AA13685; Thu, 23 Sep 93 14:08:45 -0600
  18611. Date: Thu, 23 Sep 93 14:08:45 -0600
  18612. From: michel@vette.colorado.edu (Michel Lesoinne)
  18613. Message-Id: <9309232008.AA13685@vette.colorado.edu>
  18614. To: python-list@cwi.nl
  18615. Subject: duplicate of classes (deep copy)
  18616.  
  18617. I am trying to write a program that uses fcntl.ioctl to change the condition
  18618. of a modem line and then at the end reset it to its original value.
  18619. Is there a simple function in python of all classes that does a deep
  18620. copy of an instance, similarily to dup in smalltalk.
  18621. For example I'd like the following to work correctly:
  18622.  
  18623. tio = Termio()
  18624. tio.getfrom(0) # performs a TCGETA on file 0
  18625. oldtio = tio.dup()   #Here it is. of course I can write the dup funtion but
  18626.              # it would be nice if all classes had it so that
  18627.              #it would recursively apply to members
  18628. tio.lflag = 0 ;
  18629. tio.iflag = IGNBRK ;
  18630. tio.oflag = 0 ;
  18631.  
  18632. tio.setto(0) # Change the line
  18633.  
  18634. ... # do whatever work
  18635.  
  18636. oldtio.setto(0) # reset line condition to original value
  18637.  
  18638. Thanks for any hints.
  18639.  
  18640.  
  18641. Michel
  18642.  
  18643. 
  18644. 
  18645. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  18646.     id AA27500 (5.65b/3.10/CWI-Amsterdam); Fri, 24 Sep 1993 11:48:23 +0200
  18647. Received: by voorn.cwi.nl with SMTP
  18648.     id AA13556 (5.65b/3.8/CWI-Amsterdam); Fri, 24 Sep 1993 11:48:23 +0200
  18649. Message-Id: <9309240948.AA13556=guido@voorn.cwi.nl>
  18650. To: michel@vette.colorado.edu (Michel Lesoinne)
  18651. Cc: python-list@cwi.nl
  18652. Subject: Re: duplicate of classes (deep copy) 
  18653. In-Reply-To: Your message of "Thu, 23 Sep 1993 14:08:45 MDT."
  18654.              <9309232008.AA13685@vette.colorado.edu> 
  18655. From: Guido.van.Rossum@cwi.nl
  18656. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  18657. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  18658. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  18659. Date: Fri, 24 Sep 1993 11:48:23 +0200
  18660. Sender: Guido.van.Rossum@cwi.nl
  18661.  
  18662. Michel Lesoinne writes:
  18663.  
  18664. > I am trying to write a program that uses fcntl.ioctl to change the condition
  18665. > of a modem line and then at the end reset it to its original value.
  18666. > Is there a simple function in python of all classes that does a deep
  18667. > copy of an instance, similarily to dup in smalltalk.
  18668. > For example I'd like the following to work correctly:
  18669. > tio = Termio()
  18670. > tio.getfrom(0) # performs a TCGETA on file 0
  18671. > oldtio = tio.dup()   #Here it is. of course I can write the dup funtion but
  18672. >              # it would be nice if all classes had it so that
  18673. >              #it would recursively apply to members
  18674. > tio.lflag = 0 ;
  18675. > tio.iflag = IGNBRK ;
  18676. > tio.oflag = 0 ;
  18677. > tio.setto(0) # Change the line
  18678. > ... # do whatever work
  18679. > oldtio.setto(0) # reset line condition to original value
  18680.  
  18681. No, there isn't such a feature.  In the light of Python's varying
  18682. object semantics (different for each type), deep copies are rarely as
  18683. useful as one would initially think they would be: they tend to copy
  18684. either too much or not enough, and sometimes both at the same time.
  18685. You are better off defining an operation that does exactly what you
  18686. need in a particular case.
  18687.  
  18688. Also note that a naive deep copy can get in trouble if there are
  18689. reference loops.  I don't know how smalltalk solves this.  Probably by
  18690. keeping track of objects already copied during the deep copy?  But I
  18691. presume it will also be possible to override the dup method for a
  18692. particular class, which may spoil the administration used...
  18693.  
  18694. Anyway, if you want a deep copy, here's something that should work
  18695. reasonably well.
  18696.  
  18697. -------------------------------------------------------------------------------
  18698. # Make this class a base class of each class you define
  18699. class UniversalBase:
  18700.     def dup(self): return dupinstance(self)
  18701.  
  18702. # Function to duplicate an instance
  18703. def dupinstance(x):
  18704.     new = x.__class__()
  18705.     for key in x.__dict__.keys():
  18706.         setattr(new, key, dup(getattr(x, key)))
  18707.     return new
  18708.  
  18709. ClassInstanceType = type(UniversalBase())
  18710.  
  18711. # Function to duplicate most object instances
  18712. def dup(x):
  18713.     if hasattr(x, dup):
  18714.         return x.dup()
  18715.     if type(x) is type(()):
  18716.         new = ()
  18717.         for item in x: new = new + (dup(item),)
  18718.         return new
  18719.     if type(x) is type([]):
  18720.         new = []
  18721.         for item in x: new.append(dup(item))
  18722.         return new
  18723.     if type(x) is ClassInstanceType:
  18724.         return dupinstance(x)
  18725.     return x # Assume all other interesting types are immutable
  18726.          # Not completely true but reasonable in most cases
  18727. -------------------------------------------------------------------------------
  18728.  
  18729. One problem with this: if a class has an __init__() method, it will be
  18730. called by the "x.__class__()" in dupinstance().  This may or may not
  18731. be what is desired; moreover it will fail with probablility one if the
  18732. __init__() takes one or more arguments.  The effect is that classes
  18733. with such an __init__() method are forced to define their own dup()
  18734. method (which still will call the __init__() method, but can call it
  18735. with the proper arguments.  Possibly it can be given a special
  18736. argument signalling to initialize the object from a similar one, like
  18737. copy constructors in C++.
  18738.  
  18739. Note that this problem has similarities with the problems one
  18740. encouters when trying to implement generic persistent objects in
  18741. Python.  There, too, one of the problems is to define what the
  18742. semantics should be in the light of objects that may contain
  18743. references to open files, windows, network connections, etc., and to
  18744. what extent sharing of sub-objects is incidental or essential.  I have
  18745. a feeling that this is because Python mixes mutable and immutable
  18746. objects and also allows "opaque" objects with arbitrary semantics
  18747. (e.g. defined by extension modules).
  18748.  
  18749. Maybe Jaap has some thoughts or opinions on this?
  18750.  
  18751. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  18752.  
  18753. PS: Some very interesting issues were raised on the list while I am
  18754. away.  I have read and saved everything and intend to come back to
  18755. these, if and when I have a little more time...  Bear with me...
  18756. 
  18757. 
  18758. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  18759.     id AA09973 (5.65b/3.10/CWI-Amsterdam); Sat, 25 Sep 1993 00:07:06 +0200
  18760. To: python-list@cwi.nl
  18761. Subject: dos version of 0.9.9 ???
  18762. X-Organization: Mark V Systems Ltd.
  18763. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  18764. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  18765. Date: Fri, 24 Sep 93 15:06:36 PDT
  18766. From: lance@markv.com
  18767. Sender: lance@markv.com
  18768. Message-Id:  <9309241506.aa12517@hermix.markv.com>
  18769. Source-Info:  From (or Sender) name not authenticated.
  18770.  
  18771. has anyone compiled a 0.9.9 version of Python yet?
  18772.  
  18773. --
  18774.  
  18775. Lance Ellinghouse           lance@markv.com
  18776.  
  18777. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  18778. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  18779. You can receive my Public Key by `finger lance@markv.com`
  18780. 
  18781. 
  18782. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  18783.     id AA10855 (5.65b/3.10/CWI-Amsterdam); Sat, 25 Sep 1993 02:00:29 +0200
  18784. From: Lance Ellinghouse <lance@markv.com>
  18785. X-Mailer: SCO System V Mail (version 3.2)
  18786. To: python-list@cwi.nl
  18787. Subject: rfc822 parser?
  18788. Date: Fri, 24 Sep 93 16:59:19 PDT
  18789. Message-Id:  <9309241659.aa20763@hermix.markv.com>
  18790.  
  18791. Has anyone updated or come out with a more complete 
  18792. RFC822 parser then the rfc822.py file that comes with Python?
  18793.  
  18794. Lance Ellinghouse
  18795. lance@markv.com
  18796. 
  18797. 
  18798. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  18799.     id AA26535 (5.65b/3.10/CWI-Amsterdam); Thu, 30 Sep 1993 20:00:32 +0100
  18800. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  18801.     id AA08080; Thu, 30 Sep 93 12:01:23 -0700
  18802. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  18803.     id AA24604; Thu, 30 Sep 93 11:48:49 -0700
  18804. Received: by ushqgw.sequent.com with Microsoft Mail
  18805.     id <2CAB283B@ushqgw.sequent.com>; Thu, 30 Sep 93 11:40:59 PDT
  18806. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  18807. To: guido <guido@cwi.nl>, michel <michel@vette.colorado.edu (Michel Lesoinne)>
  18808. Cc: python-list <python-list@cwi.nl>
  18809. Subject: Re: duplicate of classes (deep copy)
  18810. Date: Thu, 30 Sep 93 11:40:00 PDT
  18811. Message-Id: <2CAB283B@ushqgw.sequent.com>
  18812. Encoding: 86 TEXT
  18813. X-Mailer: Microsoft Mail V3.0
  18814.  
  18815.  
  18816.  
  18817. | Also note that a naive deep copy can get in trouble if there are
  18818. | reference loops.  I don't know how smalltalk solves this.  Probably by
  18819. | keeping track of objects already copied during the deep copy?  But I
  18820. | presume it will also be possible to override the dup method for a
  18821. | particular class, which may spoil the administration used...
  18822.  
  18823. Smalltalk doesn't have deepCopy, only shallowCopy. The regular copy will do 
  18824. a shallowCopy followed by a postCopy (to break dependents and other book 
  18825. keeping you need to do after the copy). You can redefine copy to whatever 
  18826. you like if you need it (with care, of course).
  18827.  
  18828. | One problem with this: if a class has an __init__() method, it will be
  18829. | called by the "x.__class__()" in dupinstance().  This may or may not
  18830. | be what is desired; moreover it will fail with probablility one if the
  18831. | __init__() takes one or more arguments.  The effect is that classes
  18832. | with such an __init__() method are forced to define their own dup()
  18833. | method (which still will call the __init__() method, but can call it
  18834. | with the proper arguments.  Possibly it can be given a special
  18835. | argument signalling to initialize the object from a similar one, like
  18836. | copy constructors in C++.
  18837.  
  18838. Smalltalk provides two methods for all basic operations. For new objects, 
  18839. the default method is 'new'. New is redefined by those objects that need 
  18840. additional initialization. However, there is always 'basicNew', which you 
  18841. should *never* redefine. With a structure like that you can circumvent the 
  18842. problems outlines above.
  18843.  
  18844. BTW: the way that operations like 'new' are redefined is by first calling 
  18845. the same operation in the superclass, and then performing your own 
  18846. initialization. So, if your superclass redefined 'new', the superclass 
  18847. initialization will always happen first. In Python code (just to 
  18848. illustrate):
  18849.  
  18850. class topObject():
  18851.      def new(self): return self
  18852.      def basicNew(self): return self
  18853.      def copy(self):
  18854.           new = self.shallowCopy()
  18855.           return new.postCopy()
  18856.  
  18857. class bar(topObject):
  18858.      def new(self):
  18859.           self = foo.new(self)
  18860.           return self.initialize()
  18861.  
  18862. instance = bar().new()
  18863. another_instance = instance.copy()
  18864.  
  18865. | Note that this problem has similarities with the problems one
  18866. | encouters when trying to implement generic persistent objects in
  18867. | Python.  There, too, one of the problems is to define what the
  18868. | semantics should be in the light of objects that may contain
  18869. | references to open files, windows, network connections, etc., and to
  18870. | what extent sharing of sub-objects is incidental or essential.  I have
  18871. | a feeling that this is because Python mixes mutable and immutable
  18872. | objects and also allows "opaque" objects with arbitrary semantics
  18873. | (e.g. defined by extension modules).
  18874.  
  18875. Smalltalk solves this by giving object that need it the possibility to 
  18876. 'shutdown' or 'instal' themselves. Given that the current state of Smalltalk 
  18877. is saved in the Smalltalk image, objects such as files and the window 
  18878. subsystem are notified in case the image is saved. They take the necessary 
  18879. precautions, the image gets saved, and then those objects get one of two 
  18880. messages. One is that the current session is still active, and the other is 
  18881. that a new session using the saved image started, which means they have to 
  18882. restore their state. For files, this means that they try to reconnect to all 
  18883. the files that were open when the image was saved. For windows, it means 
  18884. that all windows are reopened at the same place with the same contents. Of 
  18885. course there is some logic in place for conditions, such as restarting the 
  18886. image on a different platform where the files don't exist, or the display 
  18887. has a different size. Like I do with my Smalltalk image all the time. I 
  18888. shuttle it around between UNIX, DOS and Mac. The only thing that differs on 
  18889. these platforms is the virtual machine (binary).
  18890.  
  18891. So, in a way you get object persistence for free. However, to save objects 
  18892. outside the Smalltalk image, there is the BOSS facility, the Binary Object 
  18893. Storage Stream, which saves objects and all objects they reference 
  18894. unambiguously.
  18895.  
  18896. | Maybe Jaap has some thoughts or opinions on this?
  18897.  
  18898. Sorry it took me so long. I was busy. :-)
  18899.  
  18900.      -Jaap-
  18901. 
  18902. 
  18903. Replied: Mon, 11 Oct 1993 11:10:42 +0100
  18904. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list"
  18905. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  18906.     id AA17715 (5.65b/3.10/CWI-Amsterdam); Sun, 10 Oct 1993 04:06:55 +0100
  18907. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12044>; Sat, 9 Oct 1993 20:06:38 PDT
  18908. Received: by holmes.parc.xerox.com id <16134>; Sat, 9 Oct 1993 20:06:30 -0700
  18909. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  18910.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  18911.           Sat,  9 Oct 1993 20:06:22 -0700 (PDT)
  18912. Message-Id: <Mghrki4B0KGWN1=7FW@holmes.parc.xerox.com>
  18913. Date:     Sat, 9 Oct 1993 20:06:22 PDT
  18914. Sender: Bill Janssen <janssen@parc.xerox.com>
  18915. From: Bill Janssen <janssen@parc.xerox.com>
  18916. To: python-list@cwi.nl
  18917. Subject: Current exception
  18918.  
  18919. In an exception handler, how does one find out what the exception being
  18920. handled was?  Is it possible?  I'd like to write something like:
  18921.  
  18922. try:
  18923.     foo()
  18924. except:
  18925.     something(e)
  18926.  
  18927. where e is the specific exception.
  18928.  
  18929. Bill
  18930. -------------
  18931.  Bill Janssen  <janssen@parc.xerox.com> (415) 812-4763  FAX: (415) 812-4777
  18932.  Xerox Palo Alto Research Center, 3333 Coyote Hill Rd, Palo Alto, CA  94304
  18933.  URL:  http://pubweb.parc.xerox.com/hypertext/people/BillJanssen.html
  18934. 
  18935. 
  18936. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  18937.     id AA10026 (5.65b/3.10/CWI-Amsterdam); Mon, 11 Oct 1993 11:10:43 +0100
  18938. Received: by voorn.cwi.nl with SMTP
  18939.     id AA25021 (5.65b/3.8/CWI-Amsterdam); Mon, 11 Oct 1993 11:10:42 +0100
  18940. Message-Id: <9310111010.AA25021=guido@voorn.cwi.nl>
  18941. To: Bill Janssen <janssen@parc.xerox.com>
  18942. Cc: python-list@cwi.nl
  18943. Subject: Re: Current exception 
  18944. In-Reply-To: Your message of "Sat, 09 Oct 1993 20:06:22 MDT."
  18945.              <Mghrki4B0KGWN1=7FW@holmes.parc.xerox.com> 
  18946. From: Guido.van.Rossum@cwi.nl
  18947. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  18948. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  18949. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  18950. Date: Mon, 11 Oct 1993 11:10:42 +0100
  18951. Sender: Guido.van.Rossum@cwi.nl
  18952.  
  18953. > In an exception handler, how does one find out what the exception being
  18954. > handled was?  Is it possible?  I'd like to write something like:
  18955. > try:
  18956. >     foo()
  18957. > except:
  18958. >     something(e)
  18959. > where e is the specific exception.
  18960.  
  18961. Ah, that's an easy one, though I agree that the docs for this aren't
  18962. where you have probably been looking for them.  The module sys defines
  18963. three variables: exc_type, exc_value and exc_traceback, which are set
  18964. to the current exception when an except clause is entered.
  18965.  
  18966. Note the distinction with the three similar variables last_type, ...
  18967. which are only set when the exception isn't handled and the
  18968. interpreter prints a stack trace.  (This done so you can then import
  18969. the debugger and use it for post-mortem browsing.  Also see the -i
  18970. option to the interpreter.)
  18971.  
  18972. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  18973.  
  18974. 
  18975. 
  18976. Replied: Tue, 12 Oct 1993 10:34:50 +0100
  18977. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list"
  18978. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  18979.     id AA25335 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 00:20:02 +0100
  18980. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11747>; Mon, 11 Oct 1993 16:19:42 PDT
  18981. Received: by holmes.parc.xerox.com id <16134>; Mon, 11 Oct 1993 16:19:31 -0700
  18982. From: Bill Janssen <janssen@parc.xerox.com>
  18983. To: python-list@cwi.nl
  18984. Subject: Some python comments/questions
  18985. Message-Id: <93Oct11.161931pdt.16134@holmes.parc.xerox.com>
  18986. Date:     Mon, 11 Oct 1993 16:19:20 PDT
  18987.  
  18988. I'm happier with python than with any scripting/extension language
  18989. I've ever tried... but I have a few comments/questions:
  18990.  
  18991. 1)  I'm addicted to the C syntax of ?:, as in
  18992.  
  18993.     foo ((a < b) ? c : d);
  18994.  
  18995. Is there some equivalent in python?
  18996.  
  18997. 2) It would often be useful if there was some way to create function
  18998. objects without binding them to some name.  You can do it with
  18999. something like
  19000.  
  19001.     def makefuncobj ():
  19002.         def tmp (x, y, z):
  19003.             return (x + y * z)
  19004.         return(tmp)
  19005.  
  19006.     a = makefuncobj()
  19007.  
  19008. but you need to define a new makefuncobj for every function you
  19009. wish to dynamically create, which takes some of the dynamism
  19010. out of it :-).  I'd like to be able to have some expression whihc
  19011. evaluates to a function object without binding any names, perhaps
  19012. something like
  19013.  
  19014.     a = def *(x, y, z):
  19015.         return x + y * z;
  19016.  
  19017. You could almost do it with exec(), I'd think, except that exec()
  19018. doesn't return its value.  Are multi-line expressions even allowed?
  19019.  
  19020. 3)  Are exceptions implemented in such a way as to be thread-safe?
  19021. You speak in the EXTENDING document of a global variable that is
  19022. bound...
  19023.  
  19024. 4)  I'd like to extend python to speak ILU, the distributed interface
  19025. system we're developing here.  My thought is to add the ILU parser
  19026. and runtime kernel to the interpreter core, and then use it thusly:
  19027.  
  19028. A new call, ilu.load(<interface-file-name>), will use the ILU parser
  19029. to read and parse the file describing one or more interfaces; the
  19030. parse tree will then be interpreted in C.  In C, a new module will be
  19031. defined for every interface defined in the file; a new object type
  19032. will be defined for every object type defined in every interface; a
  19033. new method object will be generated for every method of every new
  19034. object type; every method will look something like
  19035.  
  19036.     def m(self, *args)
  19037.         return(ilu.call (self, <x>, args))
  19038.  
  19039. where <x> is a description of method m's signature.  Note that there
  19040. will be no corresponding method in C for these newly defined methods.
  19041.  
  19042. OK, so defining new modules at the C level isn't hard.  Event objects
  19043. aren't bad.  But I don't see how to define new methods or function
  19044. objects without real C functions to bind them to.
  19045.  
  19046. 5)  It's too bad that development on STDWIN is discontinued.  We use
  19047. both Macs and UNIX here, and having a portable UI interface is very
  19048. nice.  Not to mention that python with Motif is 3 MB, without Motif
  19049. it's 1 MB.
  19050.  
  19051. Bill
  19052. 
  19053. 
  19054. Replied: Tue, 12 Oct 1993 09:51:52 +0100
  19055. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list"
  19056. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  19057.     id AA26707 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 02:27:07 +0100
  19058. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11799>; Mon, 11 Oct 1993 18:26:51 PDT
  19059. Received: by holmes.parc.xerox.com id <16134>; Mon, 11 Oct 1993 18:26:44 -0700
  19060. From: Bill Janssen <janssen@parc.xerox.com>
  19061. To: python-list@cwi.nl
  19062. Subject: bug in stdwinmodule.c
  19063. Message-Id: <93Oct11.182644pdt.16134@holmes.parc.xerox.com>
  19064. Date:     Mon, 11 Oct 1993 18:26:32 PDT
  19065.  
  19066. The event WE_SIZE does not have detail (width, height), as
  19067. promised in lib/stdwinevents.py.
  19068.  
  19069. Bill
  19070. 
  19071. 
  19072. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  19073.     id AA03081 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 09:51:53 +0100
  19074. Received: by voorn.cwi.nl with SMTP
  19075.     id AA28934 (5.65b/3.8/CWI-Amsterdam); Tue, 12 Oct 1993 09:51:52 +0100
  19076. Message-Id: <9310120851.AA28934=guido@voorn.cwi.nl>
  19077. To: Bill Janssen <janssen@parc.xerox.com>
  19078. Cc: python-list@cwi.nl
  19079. Subject: Re: bug in stdwinmodule.c 
  19080. In-Reply-To: Your message of "Mon, 11 Oct 1993 18:26:32 MDT."
  19081.              <93Oct11.182644pdt.16134@holmes.parc.xerox.com> 
  19082. From: Guido.van.Rossum@cwi.nl
  19083. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19084. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19085. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19086. Date: Tue, 12 Oct 1993 09:51:52 +0100
  19087. Sender: Guido.van.Rossum@cwi.nl
  19088.  
  19089. > The event WE_SIZE does not have detail (width, height), as
  19090. > promised in lib/stdwinevents.py.
  19091.  
  19092. That comment in lib/stdwinevents.py seems to be in error.  The C
  19093. interface does not return the new width/height (you're supposed to call
  19094. wgetwinsize(); window.getwinsize() in Python).
  19095.  
  19096. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19097. 
  19098. 
  19099. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  19100.     id AA04073 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 10:34:50 +0100
  19101. Received: by voorn.cwi.nl with SMTP
  19102.     id AA29050 (5.65b/3.8/CWI-Amsterdam); Tue, 12 Oct 1993 10:34:51 +0100
  19103. Message-Id: <9310120934.AA29050=guido@voorn.cwi.nl>
  19104. To: Bill Janssen <janssen@parc.xerox.com>
  19105. Cc: python-list@cwi.nl
  19106. Subject: Re: Some python comments/questions 
  19107. In-Reply-To: Your message of "Mon, 11 Oct 1993 16:19:20 MDT."
  19108.              <93Oct11.161931pdt.16134@holmes.parc.xerox.com> 
  19109. From: Guido.van.Rossum@cwi.nl
  19110. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19111. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19112. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19113. Date: Tue, 12 Oct 1993 10:34:50 +0100
  19114. Sender: Guido.van.Rossum@cwi.nl
  19115.  
  19116. > I'm happier with python than with any scripting/extension language
  19117. > I've ever tried...but I have a few comments/questions:
  19118.  
  19119. Flatterer!
  19120.  
  19121. > 1)  I'm addicted to the C syntax of ?:, as in
  19122. >     foo ((a < b) ? c : d);
  19123. > Is there some equivalent in python?
  19124.  
  19125. Not directly.  (I guess when designing Python I was copying parts of
  19126. the design goals of ABC, which wanted to get rid of C's 13 levels of
  19127. operator priorities...)  Sometimes you can get away with "a and b"
  19128. which returns either the value of a or the value of b, not 0 or 1 as
  19129. in C -- Python's "a and b" is like "a ? a : b" except a is evaluated
  19130. only once.  Given that Python uses keywords 'and' and 'or', the '?:'
  19131. construct would probably have to be written with keywords as well --
  19132. can't think of any obvious ones though.  (Functional notation is out
  19133. since built-in functions always evaluate all their arguments.)  But I
  19134. must say that I've never missed it and in fact you're the first one
  19135. who asks for it...
  19136.  
  19137. > 2) It would often be useful if there was some way to create function
  19138. > objects without binding them to some name.  You can do it with
  19139. > something like
  19140. >     def makefuncobj ():
  19141. >         def tmp (x, y, z):
  19142. >             return (x + y * z)
  19143. >         return(tmp)
  19144. >     a = makefuncobj()
  19145. > but you need to define a new makefuncobj for every function you
  19146. > wish to dynamically create, which takes some of the dynamism
  19147. > out of it :-).  I'd like to be able to have some expression whihc
  19148. > evaluates to a function object without binding any names, perhaps
  19149. > something like
  19150. >     a = def *(x, y, z):
  19151. >         return x + y * z;
  19152. > You could almost do it with exec(), I'd think, except that exec()
  19153. > doesn't return its value.  Are multi-line expressions even allowed?
  19154.  
  19155. Multi-line expressions like this would require a major redesign of the
  19156. expression syntax.  I guess you're stuck with what you've got.
  19157. However, I don't see the reason why you don't want to bind any names.
  19158. I would personally write your first example like this:
  19159.  
  19160.     def tmp(x, y, z):
  19161.         return x + y * z
  19162.     a = tmp
  19163.  
  19164. Note that if you execute this code many times (say in a loop) the
  19165. 'def' statement will create a new function object each time.  (In fact
  19166. the semantics of a 'def' statement are assignment to the defined
  19167. function name.)
  19168.  
  19169. But maybe you can give an example where this isn't sufficient?
  19170.  
  19171. > 3)  Are exceptions implemented in such a way as to be thread-safe?
  19172. > You speak in the EXTENDING document of a global variable that is
  19173. > bound...
  19174.  
  19175. I don't think they currently are.  This is one of the areas that needs
  19176. fixing up when more machines get usable thread implementations
  19177. (currently the SGI is the only one where this really works).  It
  19178. shouldn't be too hard to fix though since most of the interface
  19179. already uses function, the global variables are static.
  19180.  
  19181. > 4)  I'd like to extend python to speak ILU, the distributed interface
  19182. > system we're developing here.  My thought is to add the ILU parser
  19183. > and runtime kernel to the interpreter core, and then use it thusly:
  19184. > A new call, ilu.load(<interface-file-name>), will use the ILU parser
  19185. > to read and parse the file describing one or more interfaces; the
  19186. > parse tree will then be interpreted in C.  In C, a new module will be
  19187. > defined for every interface defined in the file; a new object type
  19188. > will be defined for every object type defined in every interface; a
  19189. > new method object will be generated for every method of every new
  19190. > object type; every method will look something like
  19191. >     def m(self, *args)
  19192. >         return(ilu.call (self, <x>, args))
  19193. > where <x> is a description of method m's signature.  Note that there
  19194. > will be no corresponding method in C for these newly defined methods.
  19195. > OK, so defining new modules at the C level isn't hard.  Event objects
  19196. > aren't bad.  But I don't see how to define new methods or function
  19197. > objects without real C functions to bind them to.
  19198.  
  19199. This sounds remarkably similar to what the 'amoeba' module does, for
  19200. RPC in the (now almost forgotten?) distributed operating system by
  19201. that name (most of the code is in files whose name starts with 'sc'
  19202. though).  There the parsing is done outside python and loading an
  19203. interface will read the result of the parsing from a file, but that's
  19204. not an essential difference.  All methods are bound to the same C
  19205. function, the "universal RPC marshalling method", which also gets a
  19206. pointer to the result of the parsing.  The latter is actually a tiny
  19207. program for a virtual machine that does the (un)marshalling of
  19208. arguments and results.  Since the structure of the C code generated by
  19209. RPC generators for marshalling functions is usually pretty regular, it
  19210. doesn't require too much work to write such a "generic marshaller",
  19211. especially since the arguments are available as a Python tuple and not
  19212. in some machine-dependent format on the C stack.
  19213.  
  19214. > 5)  It's too bad that development on STDWIN is discontinued.  We use
  19215. > both Macs and UNIX here, and having a portable UI interface is very
  19216. > nice.  Not to mention that python with Motif is 3 MB, without Motif
  19217. > it's 1 MB.
  19218.  
  19219. Well, I'm looking for sponsors or other outside help...  If someone
  19220. would do a MS Windows port, STDWIN might become more popular, and then
  19221. I might be convinced that it's worthwile to do some more development;
  19222. STDWIN especially needs a better way to handle dialogs with buttons
  19223. and text fields etc.  Any volunteers?  (Personally, I find hacking
  19224. Python much more fun than hacking STDWIN :-)
  19225.  
  19226. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19227. 
  19228. 
  19229. Forwarded: Tue, 12 Oct 1993 16:10:44 +0100
  19230. Forwarded: "<andrewn@eaps.sussex.ac.uk>,<bevan@cs.man.ac.uk>,<peter@robots.oxford.ac.uk>,<python-users@camscan.co.uk>,<Timothy.Roscoe@cl.cam.ac.uk>,<ckh@cl.cam.ac.uk "
  19231. Forwarded: Tue, 12 Oct 1993 15:18:46 +0100
  19232. Forwarded: "<ckh@cl.cam.ac.uk>,<Timothy.Roscoe@cl.cam.ac.uk>,<python-users@camscan.co.uk>,<peter@robots.oxford.ac.uk>,<bevan@cs.man.ac.uk>,<andrewn@eaps.sussex.ac.uk "
  19233. Forwarded: Tue, 12 Oct 1993 15:10:19 +0100
  19234. Forwarded: ""andrew d. nimmo" <andrewn@eaps.sussex.ac.uk>,"stephen j. bevan" <bevan@cs.man.ac.uk>,peter ho <peter@robots.oxford.ac.uk>,python-users@camscan.co.uk,Timothy Roscoe <Timothy.Roscoe@cl.cam.ac.uk>,Chris Hadley <ckh@cl.cam.ac.uk> "
  19235. Resent: Tue, 12 Oct 1993 15:08:23 +0100
  19236. Resent: ""andrew d. nimmo" <andrewn@eaps.sussex.ac.uk>,"stephen j. bevan" <bevan@cs.m
  19237. Resent: an.ac.uk>,peter ho <peter@robots.oxford.ac.uk>,python-users@camscan.co.uk,Timoth
  19238. Resent: y Roscoe <Timothy.Roscoe@cl.cam.ac.uk>,Chris Hadley <ckh@cl.cam.ac.uk> "
  19239. Replied: Tue, 12 Oct 1993 14:45:56 +0100
  19240. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> Bill Janssen <janssen@parc.xerox.com>, python-list@cwi.nl"
  19241. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  19242.     id AA09632 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 14:16:39 +0100
  19243. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa01771;
  19244.           12 Oct 93 9:16 EDT
  19245. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  19246.     id AA14773; Tue, 12 Oct 1993 09:16:14 -0400
  19247. Date: Tue, 12 Oct 1993 09:16:14 -0400
  19248. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  19249. Message-Id: <199310121316.AA14773@elvis.med.Virginia.EDU>
  19250. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  19251. To: Bill Janssen <janssen@parc.xerox.com>
  19252. Subject: Re: Some python comments/questions [ #1: "?:" equivalent ] 
  19253. Cc: python-list@cwi.nl
  19254.  
  19255. On Oct 11, 16:19, Bill Janssen wrote:
  19256. > I'm happier with python than with any scripting/extension language
  19257. > I've ever tried... but I have a few comments/questions:
  19258. > 1)  I'm addicted to the C syntax of ?:, as in
  19259. >     foo ((a < b) ? c : d);
  19260. > Is there some equivalent in python?
  19261.  
  19262. Having played around with trying to use and/or to force python into
  19263. a more C-like expression oriented pattern lately in my Obfuscated
  19264. Python posts, this comes to mind:
  19265.  
  19266. >>> ((( 1 < 2 ) and ( 'Less Than' ) or ( 'Not Less Than' )))
  19267. 'Less Than'
  19268. >>> ((( 3 < 2 ) and ( 'Less Than' ) or ( 'Not Less Than' )))
  19269. 'Not Less Than'
  19270.  
  19271.  
  19272. But I think the following is more python-ish:
  19273.  
  19274. >>> ( 'Not Less Than', 'Less Than' )[ ( 1 < 2 ) ]
  19275. 'Less Than'
  19276. >>> ( 'Not Less Than', 'Less Than' )[ ( 3 < 2 ) ]
  19277. 'Not Less Than'
  19278.  
  19279.  
  19280. i.e. using the boolean False = 0 / True = 1 to map into a 
  19281. tuple index. BUT: since None and empty sequences are also
  19282. false and all others true, there is no guarantee that this
  19283. will work for all tests. 
  19284.  
  19285. Predictions:
  19286.  Tim will love it!
  19287.  Guido *may* feel a bit ill at our continual efforts to make python 
  19288.  look like C ! 
  19289.  
  19290.  
  19291.  
  19292. - sdm
  19293.  
  19294. 
  19295. 
  19296. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  19297.     id AA10274 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 14:45:57 +0100
  19298. Received: by voorn.cwi.nl with SMTP
  19299.     id AA00169 (5.65b/3.8/CWI-Amsterdam); Tue, 12 Oct 1993 14:45:57 +0100
  19300. Message-Id: <9310121345.AA00169=guido@voorn.cwi.nl>
  19301. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  19302. Cc: Bill Janssen <janssen@parc.xerox.com>, python-list@cwi.nl
  19303. Subject: Re: Some python comments/questions [ #1: "?:" equivalent ] 
  19304. In-Reply-To: Your message of "Tue, 12 Oct 1993 09:16:14 MET."
  19305.              <199310121316.AA14773@elvis.med.Virginia.EDU> 
  19306. From: Guido.van.Rossum@cwi.nl
  19307. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19308. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19309. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19310. Date: Tue, 12 Oct 1993 14:45:56 +0100
  19311. Sender: Guido.van.Rossum@cwi.nl
  19312.  
  19313. > >>> ((( 1 < 2 ) and ( 'Less Than' ) or ( 'Not Less Than' )))
  19314. > 'Less Than'
  19315. > >>> ((( 3 < 2 ) and ( 'Less Than' ) or ( 'Not Less Than' )))
  19316. > 'Not Less Than'
  19317.  
  19318. BUT, if you use this with generalized expressions instead of literals,
  19319. it may fail: if you evaluate "x and y or z" with x true and y false
  19320. (e.g. an empty list), result will still be z, unlike for x?y:z, where
  19321. it will be y.
  19322.  
  19323. > >>> ( 'Not Less Than', 'Less Than' )[ ( 1 < 2 ) ]
  19324. > 'Less Than'
  19325. > >>> ( 'Not Less Than', 'Less Than' )[ ( 3 < 2 ) ]
  19326. > 'Not Less Than'
  19327.  
  19328. This of course has the disadvantage that it always evaluates both
  19329. branches of the if-then-else.
  19330.  
  19331. > BUT: since None and empty sequences are also
  19332. > false and all others true, there is no guarantee that this
  19333. > will work for all tests. 
  19334.  
  19335. To convert any Boolean x into 0 or 1: "x and 1 or 0".
  19336.  
  19337. Anybody come up with a reasonable alternative syntax for x?y:z...?
  19338.  
  19339. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19340.  
  19341. PS sometimes I get mail suggesting a switch/case statement.  Do people
  19342. generally miss this?
  19343. 
  19344. 
  19345. Received: from mailgate.ericsson.se by charon.cwi.nl with SMTP
  19346.     id AA12087 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 15:52:22 +0100
  19347. Received: from eua.ericsson.se by mailgate.ericsson.se (4.1/SMI-4.1-MAILGATE1.14)
  19348.     id AA23986; Tue, 12 Oct 93 15:52:19 +0100
  19349. Received: from ms.eua.ericsson.se by eua.ericsson.se (4.1/EUA-2.1)
  19350.     id AA02615; Tue, 12 Oct 93 15:52:18 +0100
  19351. Received: from euas09c18.eua.ericsson.se by ms.eua.ericsson.se (4.1/MS-2.1)
  19352.     id AA03466; Tue, 12 Oct 93 15:52:16 +0100
  19353. From: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  19354. Received: by euas09c18.eua.ericsson.se (4.1/client-1.3)
  19355.     id AA18949; Tue, 12 Oct 93 15:52:15 +0100
  19356. Date: Tue, 12 Oct 93 15:52:15 +0100
  19357. Message-Id: <9310121452.AA18949@euas09c18.eua.ericsson.se>
  19358. To: Guido.van.Rossum@cwi.nl
  19359. Cc: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>,
  19360.         Bill Janssen <janssen@parc.xerox.com>, python-list@cwi.nl
  19361. Subject: Re: Some python comments/questions [ #1: "?:" equivalent ] 
  19362. In-Reply-To: <9310121345.AA00169=guido@voorn.cwi.nl>
  19363. References: <199310121316.AA14773@elvis.med.Virginia.EDU>
  19364.     <9310121345.AA00169=guido@voorn.cwi.nl>
  19365. Comments: Hyperbole mail buttons accepted, v3.09.
  19366.  
  19367. >>>>> Guido recently wrote:
  19368.  
  19369.   Guido> Anybody come up with a reasonable alternative syntax for
  19370.   Guido> x?y:z...?
  19371.  
  19372. ... will be shot :-) Please don't obscure the language with these type
  19373. of C things! Keep it clean.
  19374.  
  19375. If python wanted to be C we would have called it perl!
  19376.  
  19377. By the way, I miss some things from Modula and Eiffel ... ;-)
  19378.  
  19379. %% Mats
  19380. 
  19381. 
  19382. Replied: Tue, 12 Oct 1993 17:34:03 +0100
  19383. Replied: "Quentin Stafford-Fraser <Fraser@europarc.xerox.com> lutz@xvt.com (Mark Lutz), python-list"
  19384. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  19385.     id AA13356 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 16:31:06 +0100
  19386. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <11970>; Tue, 12 Oct 1993 08:30:34 PDT
  19387. Received: by eros.EuroPARC.Xerox.COM
  19388.     (5.65c/IDA-1.2.9) id AA22375; Tue, 12 Oct 1993 16:29:13 +0100
  19389. Date:     Tue, 12 Oct 1993 08:29:13 PDT
  19390. From: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  19391. Message-Id: <199310121529.AA22375@eros.EuroPARC.Xerox.COM>
  19392. To: lutz@xvt.com (Mark Lutz)
  19393. Cc: guido@cwi.nl
  19394. In-Reply-To: lutz@xvt.com's message of Mon, 11 Oct 1993 16:26:10 GMT
  19395. Subject: Re: Has anyone done a tk addition to perl?
  19396.  
  19397.  
  19398. Hi Mark -
  19399.  
  19400. > This stuff probably doesn't belong here [comp.lang.tcl]; is there any 
  19401. > interest in starting a comp.lang.python news group?
  19402.  
  19403. I think it would be great, if for no other reason than making python
  19404. more visible to the world, but I don't know enough about the protocol
  19405. for creating groups. I suspect python doesn't yet have a large enough
  19406. user community to get the required votes.
  19407.  
  19408. Guido - any thoughts? This must have come up before, but if so I missed it.
  19409. How many people are there on the mailing list?
  19410.  
  19411. Quentin
  19412.  
  19413.  
  19414. 
  19415. 
  19416. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  19417.     id AA13722 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 16:42:47 +0100
  19418. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  19419.     id AA05667; Tue, 12 Oct 1993 11:42:16 -0400
  19420. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  19421.     id AA24457; Tue, 12 Oct 93 11:42:44 EDT
  19422. Received: by kaos.ksr.com (4.1/KSR-2.0)
  19423.     id AA02396; Tue, 12 Oct 93 11:42:42 EDT
  19424. Message-Id: <9310121542.AA02396@kaos.ksr.com>
  19425. To: Guido.van.Rossum@cwi.nl, sdm7g@elvis.med.virginia.edu,
  19426.         janssen@parc.xerox.com
  19427. Subject: Re: Some python comments/questions [ #1: "?:" equivalent ]
  19428. Cc: python-list@cwi.nl
  19429. Date: Tue, 12 Oct 93 11:42:39 -0400
  19430. From: Tim Peters <tim@ksr.com>
  19431.  
  19432. Always happy to raise the level of illness <wink>:  combining the sick
  19433. ideas presented so far, I believe a faithful translation of "a?b:c" is:
  19434.  
  19435.    (a and [b] or [c])[0]
  19436.  
  19437. as in:
  19438.  
  19439. >>> (1<2 and 0 or 4)  # oops
  19440. 4
  19441. >>> (1<2 and [0] or [4])[0]  # bliss
  19442. 0
  19443. >>>
  19444.  
  19445. That is, we hide b and c inside singleton lists; then [b] and [c] are
  19446. always "true", regardless of the values of b and c; so short-circuiting
  19447. reliably returns the desired one of "[b]" and "[c]"; and strip the value
  19448. out of the list at the end.  This also worms around the multiple-evaluation
  19449. problem.
  19450.  
  19451. Of course I'd rather have my eyes eaten out by a horde of tiny wasps than
  19452. actually _use_ this idiom (or-- worse --be forced to read someone else's
  19453. code that used it), but it just goes to show once again that Guido
  19454. anticipated all possible complaints years before we thought of them <wink>.
  19455.  
  19456. Seriously, Python isn't an "expression" language (I'd call it a
  19457. "statement" language, hoping the intuitive distinction is clear), so
  19458. things "like this" don't seem (to me) to fit well in it:  I stopped
  19459. missing "?:" early on (perhaps because min and max are built in!), and by
  19460. now am 95% reconciled to assignment being a statement instead of an
  19461. expression.  If "?:" absolutely had to be added to Python, I expect that
  19462. "if a then b else c" would be an OK way to spell it.
  19463.  
  19464. on-the-other-hand-a-"case"-statement-is-a-natural!-ly y'rs  - tim
  19465.  
  19466. Tim Peters   tim@ksr.com
  19467. not speaking for Kendall Square Research Corp
  19468. 
  19469. 
  19470. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  19471.     id AA15217 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 17:34:05 +0100
  19472. Received: by voorn.cwi.nl with SMTP
  19473.     id AA01072 (5.65b/3.8/CWI-Amsterdam); Tue, 12 Oct 1993 17:34:03 +0100
  19474. Message-Id: <9310121634.AA01072=guido@voorn.cwi.nl>
  19475. To: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  19476. Cc: lutz@xvt.com (Mark Lutz), python-list@cwi.nl
  19477. Subject: Re: Has anyone done a tk addition to perl? 
  19478. In-Reply-To: Your message of "Tue, 12 Oct 1993 08:29:13 MDT."
  19479.              <199310121529.AA22375@eros.EuroPARC.Xerox.COM> 
  19480. From: Guido.van.Rossum@cwi.nl
  19481. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19482. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19483. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19484. Date: Tue, 12 Oct 1993 17:34:03 +0100
  19485. Sender: Guido.van.Rossum@cwi.nl
  19486.  
  19487. (Python-list members: I got a mail from Quentin suggesting that a
  19488. comp.lang.python group be created.  Here's my reply.)
  19489.  
  19490. The Python mailing list currently has just over 100 members, and is
  19491. growing slowly (but surely), so I don't think there is yet a
  19492. compelling reason for creating a newsgroup.
  19493.  
  19494. My personal hope is that posting 1.0 to comp.sources.unix (or .misc)
  19495. will boost the number of users by a large factor and then we'll have
  19496. to reconsider this.  I wish I could do more on publicity, e.g. put
  19497. papers in conferences (USENIX being an obvious candidate) or write a
  19498. book about Python, but the grim reality is that my research topics for
  19499. the next few years are something completely different so it isn't
  19500. likely that my employer will pay for my time writing a book about
  19501. Python, nor for traveling to a conference to talk about it.
  19502.  
  19503. I also have some vague ideas to promote Python as a multimedia
  19504. prototyping language (since that what it is being used for most
  19505. successfully here at CWI), but this will again depend on finding the
  19506. spare time to complete, unify, generalize and document the stuff we
  19507. are currently using internally (some, but not all, of which is part of
  19508. the Python release).
  19509.  
  19510. Anybody else?
  19511.  
  19512. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19513.  
  19514. 
  19515. 
  19516. To: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  19517. cc: lutz@xvt.com (Mark Lutz), python-list
  19518. Subject: Re: Has anyone done a tk addition to perl? 
  19519. In-reply-to: Your message of "Tue, 12 Oct 1993 08:29:13 MDT."
  19520.              <199310121529.AA22375@eros.EuroPARC.Xerox.COM> 
  19521. From: Guido.van.Rossum@cwi.nl
  19522. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19523. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19524. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19525. Date: Tue, 12 Oct 1993 17:34:03 +0100
  19526. Sender: guido
  19527.  
  19528. (Python-list members: I got a mail from Quentin suggesting that a
  19529. comp.lang.python group be created.  Here's my reply.)
  19530.  
  19531. The Python mailing list currently has just over 100 members, and is
  19532. growing slowly (but surely), so I don't think there is yet a
  19533. compelling reason for creating a newsgroup.
  19534.  
  19535. My personal hope is that posting 1.0 to comp.sources.unix (or .misc)
  19536. will boost the number of users by a large factor and then we'll have
  19537. to reconsider this.  I wish I could do more on publicity, e.g. put
  19538. papers in conferences (USENIX being an obvious candidate) or write a
  19539. book about Python, but the grim reality is that my research topics for
  19540. the next few years are something completely different so it isn't
  19541. likely that my employer will pay for my time writing a book about
  19542. Python, nor for traveling to a conference to talk about it.
  19543.  
  19544. I also have some vague ideas to promote Python as a multimedia
  19545. prototyping language (since that what it is being used for most
  19546. successfully here at CWI), but this will again depend on finding the
  19547. spare time to complete, unify, generalize and document the stuff we
  19548. are currently using internally (some, but not all, of which is part of
  19549. the Python release).
  19550.  
  19551. Anybody else?
  19552.  
  19553. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19554.  
  19555. 
  19556. 
  19557. Replied: Wed, 13 Oct 1993 10:28:45 +0100
  19558. Replied: "Mark Lutz <lutz@xvt.com> janssen@parc.xerox.com (Bill Janssen), python-list@cwi.nl"
  19559. Received: from csn.org by charon.cwi.nl with SMTP
  19560.     id AA18659 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 20:27:38 +0100
  19561. Received: by csn.org with UUCP id AA28243
  19562.   (5.65c/IDA-1.4.4 for python-list@cwi.nl); Tue, 12 Oct 1993 13:26:38 -0600
  19563. Received: by zeus.xvt.com id AA18144
  19564.   (5.65c/IDA-1.4.4); Tue, 12 Oct 1993 11:41:37 -0600
  19565. From: Mark Lutz <lutz@xvt.com>
  19566. Message-Id: <199310121741.AA18144@zeus.xvt.com>
  19567. Subject: Re: Some python comments/questions
  19568. To: janssen@parc.xerox.com (Bill Janssen)
  19569. Date: Tue, 12 Oct 93 11:41:36 MDT
  19570. Cc: python-list@cwi.nl
  19571. In-Reply-To: <93Oct11.161931pdt.16134@holmes.parc.xerox.com>; from "Bill Janssen" at Oct 11, 93 4:19 pm
  19572.  
  19573. You write:
  19574.  
  19575. > 2) It would often be useful if there was some way to create function
  19576. > objects without binding them to some name.  You can do it with
  19577. > something like
  19578. >     def makefuncobj ():
  19579. >         def tmp (x, y, z):
  19580. >             return (x + y * z)
  19581. >         return(tmp)
  19582. >     a = makefuncobj()
  19583. > but you need to define a new makefuncobj for every function you
  19584. > wish to dynamically create, which takes some of the dynamism
  19585. > out of it :-).  I'd like to be able to have some expression whihc
  19586. > evaluates to a function object without binding any names, perhaps
  19587. > something like
  19588. >     a = def *(x, y, z):
  19589. >         return x + y * z;
  19590. > You could almost do it with exec(), I'd think, except that exec()
  19591. > doesn't return its value.  Are multi-line expressions even allowed?
  19592.  
  19593.  
  19594. If I understand your problem correctly, you can solve it with exec() and 
  19595. strings.  Things get a little tricky with multi-line function bodies (since 
  19596. you need to remember to add '\n' and indentation in the strings) , but it 
  19597. works.  Consider the following 2 functions:
  19598.  
  19599.     def genfunc(args, expr):
  19600.         exec('def f(' + args + '): return ' + expr)
  19601.         return eval('f')
  19602.  
  19603.     def genproc(args, body):
  19604.         exec('def f(' + args + '):' + body + '\n')
  19605.         return eval('f')
  19606.  
  19607. genfunc() will create and return a new function that just returns the value 
  19608. of an expression applied to arguments.  For example:
  19609.  
  19610.     x = genfunc('x, y', '(x * y) - (x + y)')
  19611.     x(3, 4) -> 5
  19612.  
  19613. genproc() will build a function with a procedure body you pass in, which
  19614. can contain references to the symbols in the argument string:
  19615.  
  19616.     x = genproc('i, j', '\n for x in range(i,j): print x,\n print')
  19617.     x(0,10)
  19618.  
  19619. will print 0 1 2 ...9 and a new-line.
  19620.  
  19621. Note that "f" in both functions is a local variable, so you're not 
  19622. really creating new symbols.  You need to "return eval('f')", instead
  19623. of "return f" in my python version, since "f" is not known to be a
  19624. local variable statically (you could also do an initial "f = None",
  19625. to avoid having to "eval('f')").  You could also use the generated
  19626. function directly, but it's not too useful:
  19627.  
  19628.     genfunc('x, y, z', 'x * y * x')(2, 4, 6)     -> 48
  19629.  
  19630. Here's a test program that illustrates a bit more:
  19631.  
  19632.     def test():
  19633.         a, b = 3, 10
  19634.         x = genfunc('x, y', 'x * 2 + y')
  19635.         print x(2, 5)                           # 9
  19636.         print x(a, b)                           # 16
  19637.  
  19638.         y = genfunc('x, y, z', 'x * y * z')
  19639.         print y(1,2,3)                          # 6
  19640.         print y(a, b, 5)                        # 150
  19641.         print x(10, a)                          # 23
  19642.  
  19643.         z = genfunc('f, x', 'f(x, x) * 2')
  19644.         print z(x, b)                           # 60
  19645.     
  19646.         global msg; msg = 'it works.'
  19647.         a = genproc('', 'print msg * 3')          
  19648.         a()                                     # 'it works.' * 3
  19649.         genproc('', 'print msg * 4')()          # 'it works.' * 4
  19650.         
  19651.         a = genproc('x, y', '\n for i in range(x,y): print i,\n print')
  19652.         
  19653.         a(0,10)                                 # 0..9
  19654.         a(z(x,2), y(1,3,4)+5)                   # 12..16
  19655.         
  19656.         b = genproc('f, m', 'f(0,10); print m')
  19657.         b(a, 'all done.')                       # 0..9, 'all done.'
  19658.     
  19659.         c = genproc('l, r', 'l; exec(r)')
  19660.         c(a(0,10), 'print \'all done.\'')       # ditto
  19661.     
  19662.         d = genproc('l, r', 'exec(l); exec(r)')
  19663.         d('for i in range(0,10): print i,', 'print \'all done.\'')
  19664.         
  19665.  
  19666. Mark Lutz
  19667. lutz@xvt.com
  19668. 
  19669. 
  19670. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  19671.     id AA17877 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 19:43:48 +0100
  19672. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  19673.     id AA07820; Tue, 12 Oct 1993 14:43:27 -0400
  19674. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  19675.     id AA26100; Tue, 12 Oct 93 14:43:57 EDT
  19676. Received: by kaos.ksr.com (4.1/KSR-2.0)
  19677.     id AA10884; Tue, 12 Oct 93 14:43:55 EDT
  19678. Message-Id: <9310121843.AA10884@kaos.ksr.com>
  19679. To: janssen@parc.xerox.com
  19680. Subject: Anonymous functions (was Re: Some python comments/questions)
  19681. Cc: python-list@cwi.nl
  19682. Date: Tue, 12 Oct 93 14:43:54 -0400
  19683. From: Tim Peters <tim@ksr.com>
  19684.  
  19685. > 2) It would often be useful if there was some way to create function
  19686. > objects without binding them to some name.  You can do it with
  19687. > something like
  19688. >
  19689. >       def makefuncobj ():
  19690. >               def tmp (x, y, z):
  19691. >                       return (x + y * z)
  19692. >               return(tmp)
  19693. >
  19694. >       a = makefuncobj()
  19695. >
  19696. > but you need to define a new makefuncobj for every function you
  19697. > wish to dynamically create, which takes some of the dynamism
  19698. > out of it :-).  ...
  19699.  
  19700. You might find the following handy, for creating simple "one-liner"
  19701. functions on the fly:
  19702.  
  19703. from string import find
  19704.  
  19705. def func( f ):
  19706.     i = find( f, ':' )
  19707.     if i < 0:
  19708.         raise ValueError, 'need colon in function string ' + `f`
  19709.  
  19710.     args, body = f[:i], f[i+1:]
  19711.     f = 'def f(' + args + '): return ' + body
  19712.  
  19713.     bad = 1                             # guilty until proven innocent
  19714.     try:
  19715.         exec( f )                       # creates local func 'f'
  19716.         bad = 0
  19717.     finally:
  19718.         if bad:
  19719.             print 'Error in func:  couldn\'t exec ' + `f`
  19720.  
  19721.     return f
  19722.  
  19723. This takes a string of the form
  19724.  
  19725.     [arglist] ':' expression
  19726.  
  19727. as its argument, and returns the function defined by
  19728.  
  19729.     'def f(' arglist '): return ' expression
  19730.  
  19731. The name 'f' is local to the invocation of 'func', so effectively
  19732. vanishes when 'func' returns (the binding of the _name_ 'f' to the
  19733. function object vanishes, but the function object itself does not); so
  19734. from the point of view of the caller, the function returned by 'func' is
  19735. anonymous (cannot interfere with name bindings in the caller, or indeed
  19736. even be invoked by name).
  19737.  
  19738. For example, given function
  19739.  
  19740. def map( f, x ):
  19741.     y = []
  19742.     for e in x:
  19743.         y.append( f(e) )
  19744.     return y
  19745.  
  19746. we have
  19747.  
  19748. >>> map( func('x: x*x'), range(8) )
  19749. [0, 1, 4, 9, 16, 25, 36, 49]
  19750. >>>
  19751.  
  19752. Or
  19753.  
  19754. >>> flist = map( func, ['x:x+x', 'y:y*y', 'z:42'] )
  19755. >>> for f in flist:
  19756. ...   print f(3)
  19757. ...
  19758. 6
  19759. 9
  19760. 42
  19761. >>>
  19762.  
  19763. I often find 'func' to be handy, in conjunction with LISPish functions
  19764. like 'map', when doing interactive data crunching.
  19765.  
  19766. > You could almost do it with exec(), I'd think, except that exec()
  19767. > doesn't return its value.
  19768.  
  19769. Right, that's why the exec is packaged inside a function here.
  19770.  
  19771. > Are multi-line expressions even allowed?
  19772.  
  19773. The context ("allowed" where?) wasn't clear to me.  exec will crunch any
  19774. legit Python program text, and it's certainly possible to generalize
  19775. 'func' to allow creating anonymous functions built out of arbitrary
  19776. Python code.  But note that representing complex functions as strings
  19777. gets clumsy, because you have to get the newlines, and the right amount
  19778. of leading indentation, in the right places (or, define an un-Python-like
  19779. string representation, and program a fancier 'func' to translate that
  19780. into legit Python before handing it to 'exec').
  19781.  
  19782. the-function-that-is-named-is-not-the-true-function-ly y'rs  - tim
  19783.  
  19784. Tim Peters   tim@ksr.com
  19785. not speaking for Kendall Square Research Corp
  19786. 
  19787. 
  19788. Replied: Wed, 13 Oct 1993 10:36:58 +0100
  19789. Replied: "Mark Lutz <lutz@xvt.com> "
  19790. Received: from csn.org by charon.cwi.nl with SMTP
  19791.     id AA21810 (5.65b/3.10/CWI-Amsterdam); Tue, 12 Oct 1993 23:42:25 +0100
  19792. Received: by csn.org with UUCP id AA20093
  19793.   (5.65c/IDA-1.4.4 for python-list@cwi.nl); Tue, 12 Oct 1993 16:15:58 -0600
  19794. Received: by zeus.xvt.com id AA22425
  19795.   (5.65c/IDA-1.4.4); Tue, 12 Oct 1993 15:13:31 -0600
  19796. From: Mark Lutz <lutz@xvt.com>
  19797. Message-Id: <199310122113.AA22425@zeus.xvt.com>
  19798. Subject: Re: Some python comments/questions (correction)
  19799. To: janssen@parc.xerox.com (Bill Janssen)
  19800. Date: Tue, 12 Oct 93 15:13:31 MDT
  19801. Cc: python-list@cwi.nl
  19802. In-Reply-To: <93Oct11.161931pdt.16134@holmes.parc.xerox.com>; from "Bill Janssen" at Oct 11, 93 4:19 pm
  19803.  
  19804. A minor correction; I wrote (much too fast...):
  19805.  
  19806. >    genfunc('x, y, z', 'x * y * x')(2, 4, 6)     -> 48
  19807.  
  19808. Of course, it should read:
  19809.  
  19810.      genfunc('x, y, z', 'x * y * z')(2, 4, 6)     -> 48
  19811.  
  19812. Sorry if this caused confusion.  Another poster also points 
  19813. out that anonymous functions _are_ useful in Lisp-like mapping
  19814. functions.
  19815.  
  19816.  
  19817. And now for something completely different... 
  19818.  
  19819. 1) What are the major differences between python 0.9.8 to 0.9.9?
  19820. [I'd ftp the new system , but I don't have convenient ftp 
  19821. access at the moment.]
  19822.  
  19823. 2) Is there any date in mind for release 1.0 to come out?
  19824. Again, what might that introduce?
  19825.  
  19826.  
  19827. Thanks,
  19828. lutz@xvt.com
  19829. 
  19830. 
  19831. Replied: Wed, 13 Oct 1993 09:43:06 +0100
  19832. Replied: "python-list@cwi.nl "
  19833. Received: from boring.cwi.nl by charon.cwi.nl with SMTP
  19834.     id AA23109 (5.65b/3.10/CWI-Amsterdam); Wed, 13 Oct 1993 00:27:21 +0100
  19835. Received: by boring.cwi.nl 
  19836.     id AA05848 (4.1/2.10/CWI-Amsterdam); Wed, 13 Oct 93 00:27:21 +0100
  19837. Date: Wed, 13 Oct 93 00:27:21 +0100
  19838. From: Dik.Winter@cwi.nl
  19839. Message-Id: <9310122327.AA05848.dik@boring.cwi.nl>
  19840. To: python-list@cwi.nl
  19841. Subject: Re: Some python comments/questions (correction)
  19842.  
  19843.  > 1) What are the major differences between python 0.9.8 to 0.9.9?
  19844.  > [I'd ftp the new system , but I don't have convenient ftp 
  19845.  > access at the moment.]
  19846.  
  19847.  > 2) Is there any date in mind for release 1.0 to come out?
  19848.  > Again, what might that introduce?
  19849.  
  19850. Trust Guido to come up with 0.9.9.1 next ;-).
  19851. 
  19852. 
  19853. Replied: Wed, 13 Oct 1993 10:57:41 +0100
  19854. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list"
  19855. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  19856.     id AA24506 (5.65b/3.10/CWI-Amsterdam); Wed, 13 Oct 1993 02:03:43 +0100
  19857. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11970>; Tue, 12 Oct 1993 18:03:12 PDT
  19858. Received: by holmes.parc.xerox.com id <16134>; Tue, 12 Oct 1993 18:03:03 -0700
  19859. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  19860.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  19861.           Tue, 12 Oct 1993 18:02:56 -0700 (PDT)
  19862. Message-Id: <8gipD08B0KGWFDkAp_@holmes.parc.xerox.com>
  19863. Date:     Tue, 12 Oct 1993 18:02:56 PDT
  19864. Sender: Bill Janssen <janssen@parc.xerox.com>
  19865. From: Bill Janssen <janssen@parc.xerox.com>
  19866. To: python-list@cwi.nl
  19867. Subject: Python and UI
  19868.  
  19869. Another tack might be to drop the use of STDWIN, and substitute
  19870. something else that's already been ported.  SUIT comes to mind, for
  19871. example.
  19872.  
  19873. A system that might better match Python's perspicuity, though, is
  19874. something more like Joel Bartlett's EZD
  19875. (ftp://gatekeeper.dec.com/pub/DEC/ezd/).
  19876.  
  19877. Bill
  19878. 
  19879. 
  19880. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  19881.     id AA02105 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 09:43:05 +0100
  19882. Received: by voorn.cwi.nl with SMTP
  19883.     id AA02694 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 09:43:06 +0100
  19884. Message-Id: <9310130843.AA02694=guido@voorn.cwi.nl>
  19885. To: python-list@cwi.nl
  19886. Subject: Re: Some python comments/questions (correction) 
  19887. In-Reply-To: Your message of "Wed, 13 Oct 1993 00:27:21 MET."
  19888.              <9310122327.AA05848.dik@boring.cwi.nl> 
  19889. From: Guido.van.Rossum@cwi.nl
  19890. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19891. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19892. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19893. Date: Wed, 13 Oct 1993 09:43:06 +0100
  19894. Sender: Guido.van.Rossum@cwi.nl
  19895.  
  19896. >  > 2) Is there any date in mind for release 1.0 to come out?
  19897. >  > Again, what might that introduce?
  19898. > Trust Guido to come up with 0.9.9.1 next ;-).
  19899.  
  19900. Actually I'm firmly committed to post it to comp.sources.unix (or
  19901. .misc?  which would be better?) before the end of 1993.  Of course it
  19902. may be almost identical to 0.9.9 except for the name space changes...
  19903.  
  19904. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19905. 
  19906. 
  19907. To: python-list@cwi.nl
  19908. Subject: Re: Some python comments/questions (correction) 
  19909. In-reply-to: Your message of "Wed, 13 Oct 1993 00:27:21 MET."
  19910.              <9310122327.AA05848.dik@boring.cwi.nl> 
  19911. From: Guido.van.Rossum@cwi.nl
  19912. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19913. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19914. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19915. Date: Wed, 13 Oct 1993 09:43:06 +0100
  19916. Sender: guido
  19917.  
  19918. >  > 2) Is there any date in mind for release 1.0 to come out?
  19919. >  > Again, what might that introduce?
  19920. > Trust Guido to come up with 0.9.9.1 next ;-).
  19921.  
  19922. Actually I'm firmly committed to post it to comp.sources.unix (or
  19923. .misc?  which would be better?) before the end of 1993.  Of course it
  19924. may be almost identical to 0.9.9 except for the name space changes...
  19925.  
  19926. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  19927. 
  19928. 
  19929. Replied: Wed, 13 Oct 1993 11:07:03 +0100
  19930. Replied: "Quentin Stafford-Fraser <Fraser@europarc.xerox.com> python-list@cwi.nl"
  19931. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  19932.     id AA00984 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 10:25:26 +0100
  19933. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <12073>; Wed, 13 Oct 1993 02:25:09 PDT
  19934. Received: by eros.EuroPARC.Xerox.COM with SMTP
  19935.     (5.65c/IDA-1.2.9) id AA28934; Wed, 13 Oct 1993 10:24:18 +0100
  19936. Message-Id: <199310130924.AA28934@eros.EuroPARC.Xerox.COM>
  19937. To: python-list@cwi.nl
  19938. Subject: Re: Some python comments/questions (correction) 
  19939. In-Reply-To: Your message of "Wed, 13 Oct 93 01:43:06 PDT."
  19940.              <9310130843.AA02694=guido@voorn.cwi.nl> 
  19941. Date:     Wed, 13 Oct 1993 02:24:17 PDT
  19942. From: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  19943.  
  19944.  
  19945. > Actually I'm firmly committed to post it to comp.sources.unix (or
  19946. > .misc?  which would be better?) before the end of 1993.  Of course it
  19947. > may be almost identical to 0.9.9 except for the name space changes...
  19948.  
  19949. Good - I'm thinking of doing a Modula-3 interface, but I'm waiting for the name changes...
  19950.  
  19951. I have to say that I don't think the 'primes' program included in the BLURB document is a good example of Python's clarity and ease-of-use.  We need a clear bit of sample code that makes people say "Hey, this is worth downloading" when it appears on comp.sources.
  19952.  
  19953. Anybody like to volunteer some?
  19954.  
  19955. Quentin
  19956.  
  19957.  
  19958. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19959. Quentin Stafford-Fraser                        Tel:  +44 223 341521             
  19960. Rank Xerox EuroPARC,                           Fax:  +44 223 341510     
  19961. 61 Regent Street,                              Home: +44 223 324451
  19962. Cambridge, CB2 1AB
  19963. United Kingdom                                 Fraser@europarc.xerox.com 
  19964.  
  19965. You can retrieve my pgp public key using "finger qs101@osprey.cl.cam.ac.uk"
  19966. 
  19967. 
  19968. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  19969.     id AA01023 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 10:28:47 +0100
  19970. Received: by voorn.cwi.nl with SMTP
  19971.     id AA02952 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 10:28:46 +0100
  19972. Message-Id: <9310130928.AA02952=guido@voorn.cwi.nl>
  19973. To: Mark Lutz <lutz@xvt.com>
  19974. Cc: janssen@parc.xerox.com (Bill Janssen), python-list@cwi.nl
  19975. Subject: Re: Some python comments/questions 
  19976. In-Reply-To: Your message of "Tue, 12 Oct 1993 11:41:36 MDT."
  19977.              <199310121741.AA18144@zeus.xvt.com> 
  19978. From: Guido.van.Rossum@cwi.nl
  19979. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  19980. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  19981. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  19982. Date: Wed, 13 Oct 1993 10:28:45 +0100
  19983. Sender: Guido.van.Rossum@cwi.nl
  19984.  
  19985. > Note that "f" in both functions is a local variable, so you're not 
  19986. > really creating new symbols.  You need to "return eval('f')", instead
  19987. > of "return f" in my python version, since "f" is not known to be a
  19988. > local variable statically (you could also do an initial "f = None",
  19989. > to avoid having to "eval('f')").
  19990.  
  19991. This illustrates an interesting fine point of Python's eval/exec
  19992. semantics: if exec() introduces a new name in the local namespace, the
  19993. "compiler" can't know about it and any references to it later will
  19994. fail mysteriously (since it actually exists in the dictionary of local
  19995. variables but the generated pseudo code will use a "global variable
  19996. reference" and fail to find it).  For example, if you write
  19997.  
  19998.     i = 1
  19999.  
  20000.     def func():
  20001.         j = 1
  20002.         return i, j
  20003.  
  20004. then the "compiler" (which generates pseudo code for the Python
  20005. interpreter) sees that there is a local variable j bot no local
  20006. variable i, so it will generate a local reference for returning j but
  20007. a global reference for returning i.  The reason for doing so is that
  20008. this speeds up both kinds of references: global references don't first
  20009. have to do an unsuccessful lookup in the dictionary of local
  20010. variables, and (starting in 0.9.9) local references are speeded up by
  20011. using an index into a list instead of a dictionary lookup.  Note that
  20012. any assignment by definition creates a local variable unless
  20013. explicitly declared global first -- 'global' is in fact one of the few
  20014. statements that is interpreted at compile time instead of at run-time.
  20015. Also note that for this purpose the compiler keeps track of all local
  20016. variables, but not of all global variables.  Finally, for the really
  20017. inquiring minds, built-in functions (e.g. len()) and names (i.e. None)
  20018. are treated as globals here and they *do* suffer one unsuccessful
  20019. lookup in the table of globals.  This means you can override built-in
  20020. names with local or global names.  You can even change the set
  20021. of built-in functions by modifying the built-in module 'builtin' (soon
  20022. to be renamed to '__builtin__' to emphasize its special status, like
  20023. '__main__').
  20024.  
  20025. The effect of all this is that, if the only assignment to a variable
  20026. is hidden inside an exec(), the compiler can't know about it at the
  20027. time the containing code is being compiled and it will thus assume it
  20028. is a global variable.  (The exec() can't modify the containing code --
  20029. it only generates new code for what is passed to it.)
  20030.  
  20031. My preferred solution is indeed an initial assignment "f = None".  You
  20032. deserve credit for inventing the alternative "return eval('f')".
  20033. However, though shorter in lines of code, involves the overhead of
  20034. parsing the string 'f' on each execution.
  20035.  
  20036. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20037. 
  20038. 
  20039. To: Mark Lutz <lutz@xvt.com>
  20040. cc: janssen@parc.xerox.com (Bill Janssen), python-list@cwi.nl
  20041. Subject: Re: Some python comments/questions 
  20042. In-reply-to: Your message of "Tue, 12 Oct 1993 11:41:36 MDT."
  20043.              <199310121741.AA18144@zeus.xvt.com> 
  20044. From: Guido.van.Rossum@cwi.nl
  20045. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20046. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20047. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20048. Date: Wed, 13 Oct 1993 10:28:45 +0100
  20049. Sender: guido
  20050.  
  20051. > Note that "f" in both functions is a local variable, so you're not 
  20052. > really creating new symbols.  You need to "return eval('f')", instead
  20053. > of "return f" in my python version, since "f" is not known to be a
  20054. > local variable statically (you could also do an initial "f = None",
  20055. > to avoid having to "eval('f')").
  20056.  
  20057. This illustrates an interesting fine point of Python's eval/exec
  20058. semantics: if exec() introduces a new name in the local namespace, the
  20059. "compiler" can't know about it and any references to it later will
  20060. fail mysteriously (since it actually exists in the dictionary of local
  20061. variables but the generated pseudo code will use a "global variable
  20062. reference" and fail to find it).  For example, if you write
  20063.  
  20064.     i = 1
  20065.  
  20066.     def func():
  20067.         j = 1
  20068.         return i, j
  20069.  
  20070. then the "compiler" (which generates pseudo code for the Python
  20071. interpreter) sees that there is a local variable j bot no local
  20072. variable i, so it will generate a local reference for returning j but
  20073. a global reference for returning i.  The reason for doing so is that
  20074. this speeds up both kinds of references: global references don't first
  20075. have to do an unsuccessful lookup in the dictionary of local
  20076. variables, and (starting in 0.9.9) local references are speeded up by
  20077. using an index into a list instead of a dictionary lookup.  Note that
  20078. any assignment by definition creates a local variable unless
  20079. explicitly declared global first -- 'global' is in fact one of the few
  20080. statements that is interpreted at compile time instead of at run-time.
  20081. Also note that for this purpose the compiler keeps track of all local
  20082. variables, but not of all global variables.  Finally, for the really
  20083. inquiring minds, built-in functions (e.g. len()) and names (i.e. None)
  20084. are treated as globals here and they *do* suffer one unsuccessful
  20085. lookup in the table of globals.  This means you can override built-in
  20086. names with local or global names.  You can even change the set
  20087. of built-in functions by modifying the built-in module 'builtin' (soon
  20088. to be renamed to '__builtin__' to emphasize its special status, like
  20089. '__main__').
  20090.  
  20091. The effect of all this is that, if the only assignment to a variable
  20092. is hidden inside an exec(), the compiler can't know about it at the
  20093. time the containing code is being compiled and it will thus assume it
  20094. is a global variable.  (The exec() can't modify the containing code --
  20095. it only generates new code for what is passed to it.)
  20096.  
  20097. My preferred solution is indeed an initial assignment "f = None".  You
  20098. deserve credit for inventing the alternative "return eval('f')".
  20099. However, though shorter in lines of code, involves the overhead of
  20100. parsing the string 'f' on each execution.
  20101.  
  20102. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20103. 
  20104. 
  20105. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  20106.     id AA01475 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 10:57:42 +0100
  20107. Received: by voorn.cwi.nl with SMTP
  20108.     id AA03031 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 10:57:41 +0100
  20109. Message-Id: <9310130957.AA03031=guido@voorn.cwi.nl>
  20110. To: Bill Janssen <janssen@parc.xerox.com>
  20111. Cc: python-list@cwi.nl
  20112. Subject: Re: Python and UI 
  20113. In-Reply-To: Your message of "Tue, 12 Oct 1993 18:02:56 MDT."
  20114.              <8gipD08B0KGWFDkAp_@holmes.parc.xerox.com> 
  20115. From: Guido.van.Rossum@cwi.nl
  20116. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20117. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20118. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20119. Date: Wed, 13 Oct 1993 10:57:41 +0100
  20120. Sender: Guido.van.Rossum@cwi.nl
  20121.  
  20122. > Another tack might be to drop the use of STDWIN, and substitute
  20123. > something else that's already been ported.  SUIT comes to mind, for
  20124. > example.
  20125.  
  20126. I have had a look at SUIT, and even have half a Python interface for
  20127. it lying on a shelf somewhere.  (Someone want to finish it?)  I like
  20128. what SUIT does for simple interfaces but am not convinced that it can
  20129. replace STDWIN -- I seem to remember that you always get exactly one
  20130. top-level window, and I don't recollect there being a non-X11 version.
  20131. (In fact, I see SUIT as almost complementary to STDWIN.)
  20132.  
  20133. > A system that might better match Python's perspicuity, though, is
  20134. > something more like Joel Bartlett's EZD
  20135. > (ftp://gatekeeper.dec.com/pub/DEC/ezd/).
  20136.  
  20137. Haven't seen it yet.  Anybody else know about it?
  20138.  
  20139. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20140. 
  20141. 
  20142. To: Bill Janssen <janssen@parc.xerox.com>
  20143. cc: python-list
  20144. Subject: Re: Python and UI 
  20145. In-reply-to: Your message of "Tue, 12 Oct 1993 18:02:56 MDT."
  20146.              <8gipD08B0KGWFDkAp_@holmes.parc.xerox.com> 
  20147. From: Guido.van.Rossum@cwi.nl
  20148. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20149. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20150. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20151. Date: Wed, 13 Oct 1993 10:57:41 +0100
  20152. Sender: guido
  20153.  
  20154. > Another tack might be to drop the use of STDWIN, and substitute
  20155. > something else that's already been ported.  SUIT comes to mind, for
  20156. > example.
  20157.  
  20158. I have had a look at SUIT, and even have half a Python interface for
  20159. it lying on a shelf somewhere.  (Someone want to finish it?)  I like
  20160. what SUIT does for simple interfaces but am not convinced that it can
  20161. replace STDWIN -- I seem to remember that you always get exactly one
  20162. top-level window, and I don't recollect there being a non-X11 version.
  20163. (In fact, I see SUIT as almost complementary to STDWIN.)
  20164.  
  20165. > A system that might better match Python's perspicuity, though, is
  20166. > something more like Joel Bartlett's EZD
  20167. > (ftp://gatekeeper.dec.com/pub/DEC/ezd/).
  20168.  
  20169. Haven't seen it yet.  Anybody else know about it?
  20170.  
  20171. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20172. 
  20173. 
  20174. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  20175.     id AA01721 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 11:07:04 +0100
  20176. Received: by voorn.cwi.nl with SMTP
  20177.     id AA03066 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 11:07:03 +0100
  20178. Message-Id: <9310131007.AA03066=guido@voorn.cwi.nl>
  20179. To: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  20180. Cc: python-list@cwi.nl
  20181. Subject: Re: Some python comments/questions (correction) 
  20182. In-Reply-To: Your message of "Wed, 13 Oct 1993 02:24:17 MDT."
  20183.              <199310130924.AA28934@eros.EuroPARC.Xerox.COM> 
  20184. From: Guido.van.Rossum@cwi.nl
  20185. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20186. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20187. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20188. Date: Wed, 13 Oct 1993 11:07:03 +0100
  20189. Sender: Guido.van.Rossum@cwi.nl
  20190.  
  20191. > Good - I'm thinking of doing a Modula-3 interface, but I'm waiting
  20192. > for the name changes...
  20193.  
  20194. You don't have to wait for the name changes -- all the new names are
  20195. in the 0.9.9 release (see python/misc/NAMING and
  20196. python/misc/RENAMING).  The new filenames aren't in place yet but you
  20197. can count on <Py/Python.h> to replace "allobjects.h" plus a few more
  20198. that are needed by all or most extension modules.
  20199.  
  20200. > I have to say that I don't think the 'primes' program included in
  20201. > the BLURB document is a good example of Python's clarity and
  20202. > ease-of-use.  We need a clear bit of sample code that makes people say
  20203. > "Hey, this is worth downloading" when it appears on comp.sources.
  20204.  
  20205. Hmm, that is indeed a somewhat convoluted bit of code.  I think we
  20206. would need several short examples, highlighting different aspects of
  20207. the language: a simple numerical algorithm (printing Fibonacci
  20208. numbers?  who can think of a more interesting example?), some I/O and
  20209. system calls, some object-oriented stuff, some windowing (would an
  20210. example using Motif be a better choice than one for STDWIN?).
  20211.  
  20212. I guess nothing would convince die-hard perl hacks because there's
  20213. always a shorter way in Perl, but for those who are afraid of Perl it
  20214. might actually work to compare a few cases of Python and Perl code...
  20215. (Though of course it is much more dramatic to compare Python with
  20216. equivalent C programs...)
  20217.  
  20218. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20219. 
  20220. 
  20221. To: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  20222. cc: python-list@cwi.nl
  20223. Subject: Re: Some python comments/questions (correction) 
  20224. In-reply-to: Your message of "Wed, 13 Oct 1993 02:24:17 MDT."
  20225.              <199310130924.AA28934@eros.EuroPARC.Xerox.COM> 
  20226. From: Guido.van.Rossum@cwi.nl
  20227. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20228. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20229. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20230. Date: Wed, 13 Oct 1993 11:07:03 +0100
  20231. Sender: guido
  20232.  
  20233. > Good - I'm thinking of doing a Modula-3 interface, but I'm waiting
  20234. > for the name changes...
  20235.  
  20236. You don't have to wait for the name changes -- all the new names are
  20237. in the 0.9.9 release (see python/misc/NAMING and
  20238. python/misc/RENAMING).  The new filenames aren't in place yet but you
  20239. can count on <Py/Python.h> to replace "allobjects.h" plus a few more
  20240. that are needed by all or most extension modules.
  20241.  
  20242. > I have to say that I don't think the 'primes' program included in
  20243. > the BLURB document is a good example of Python's clarity and
  20244. > ease-of-use.  We need a clear bit of sample code that makes people say
  20245. > "Hey, this is worth downloading" when it appears on comp.sources.
  20246.  
  20247. Hmm, that is indeed a somewhat convoluted bit of code.  I think we
  20248. would need several short examples, highlighting different aspects of
  20249. the language: a simple numerical algorithm (printing Fibonacci
  20250. numbers?  who can think of a more interesting example?), some I/O and
  20251. system calls, some object-oriented stuff, some windowing (would an
  20252. example using Motif be a better choice than one for STDWIN?).
  20253.  
  20254. I guess nothing would convince die-hard perl hacks because there's
  20255. always a shorter way in Perl, but for those who are afraid of Perl it
  20256. might actually work to compare a few cases of Python and Perl code...
  20257. (Though of course it is much more dramatic to compare Python with
  20258. equivalent C programs...)
  20259.  
  20260. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20261. 
  20262. 
  20263. Replied: Wed, 13 Oct 1993 11:34:24 +0100
  20264. Replied: "Quentin Stafford-Fraser <Fraser@europarc.xerox.com> python-list@cwi.nl"
  20265. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  20266.     id AA02232 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 11:30:48 +0100
  20267. Received: from eros.EuroPARC.Xerox.COM ([13.1.252.143]) by alpha.xerox.com with SMTP id <12093>; Wed, 13 Oct 1993 03:30:24 PDT
  20268. Received: by eros.EuroPARC.Xerox.COM with SMTP
  20269.     (5.65c/IDA-1.2.9) id AA29223; Wed, 13 Oct 1993 11:29:34 +0100
  20270. Message-Id: <199310131029.AA29223@eros.EuroPARC.Xerox.COM>
  20271. To: python-list@cwi.nl
  20272. Subject: Re: Some python comments/questions (correction) 
  20273. In-Reply-To: Your message of "Wed, 13 Oct 93 03:07:03 PDT."
  20274.              <9310131007.AA03066=guido@voorn.cwi.nl> 
  20275. Date:     Wed, 13 Oct 1993 03:29:33 PDT
  20276. From: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  20277.  
  20278.  
  20279. > You don't have to wait for the name changes -- all the new names are
  20280. > in the 0.9.9 release (see python/misc/NAMING and
  20281. > python/misc/RENAMING). 
  20282.  
  20283. Ah, well they're there if you're using C, because they're #define'd, but if you're using another language then you need to know the names that will be seen by the linker.
  20284.  
  20285. Quentin
  20286.  
  20287.  
  20288. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20289. Quentin Stafford-Fraser                        Tel:  +44 223 341521             
  20290. Rank Xerox EuroPARC,                           Fax:  +44 223 341510     
  20291. 61 Regent Street,                              Home: +44 223 324451
  20292. Cambridge, CB2 1AB
  20293. United Kingdom                                 Fraser@europarc.xerox.com 
  20294.  
  20295. You can retrieve my pgp public key using "finger qs101@osprey.cl.cam.ac.uk"
  20296. 
  20297. 
  20298. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  20299.     id AA02307 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 11:34:25 +0100
  20300. Received: by voorn.cwi.nl with SMTP
  20301.     id AA03159 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 11:34:24 +0100
  20302. Message-Id: <9310131034.AA03159=guido@voorn.cwi.nl>
  20303. To: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  20304. Cc: python-list@cwi.nl
  20305. Subject: Re: Some python comments/questions (correction) 
  20306. In-Reply-To: Your message of "Wed, 13 Oct 1993 03:29:33 MDT."
  20307.              <199310131029.AA29223@eros.EuroPARC.Xerox.COM> 
  20308. From: Guido.van.Rossum@cwi.nl
  20309. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20310. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20311. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20312. Date: Wed, 13 Oct 1993 11:34:24 +0100
  20313. Sender: Guido.van.Rossum@cwi.nl
  20314.  
  20315. > > You don't have to wait for the name changes -- all the new names are
  20316. > > in the 0.9.9 release (see python/misc/NAMING and
  20317. > > python/misc/RENAMING). 
  20318. >
  20319. > Ah, well they're there if you're using C, because they're #define'd,
  20320. > but if you're using another language then you need to know the names
  20321. > that will be seen by the linker.
  20322.  
  20323. Well you could run the script "python/demo/scripts/fixcid.py" over the
  20324. distributed source.  This should fix 99% of the identifiers...  Or you
  20325. could invert the definitions of the "rename1.h" header file.
  20326.  
  20327. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20328. 
  20329. 
  20330. To: Quentin Stafford-Fraser <Fraser@europarc.xerox.com>
  20331. cc: python-list@cwi.nl
  20332. Subject: Re: Some python comments/questions (correction) 
  20333. In-reply-to: Your message of "Wed, 13 Oct 1993 03:29:33 MDT."
  20334.              <199310131029.AA29223@eros.EuroPARC.Xerox.COM> 
  20335. From: Guido.van.Rossum@cwi.nl
  20336. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20337. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20338. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20339. Date: Wed, 13 Oct 1993 11:34:24 +0100
  20340. Sender: guido
  20341.  
  20342. > > You don't have to wait for the name changes -- all the new names are
  20343. > > in the 0.9.9 release (see python/misc/NAMING and
  20344. > > python/misc/RENAMING). 
  20345. >
  20346. > Ah, well they're there if you're using C, because they're #define'd,
  20347. > but if you're using another language then you need to know the names
  20348. > that will be seen by the linker.
  20349.  
  20350. Well you could run the script "python/demo/scripts/fixcid.py" over the
  20351. distributed source.  This should fix 99% of the identifiers...  Or you
  20352. could invert the definitions of the "rename1.h" header file.
  20353.  
  20354. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20355. 
  20356. 
  20357. Replied: Wed, 13 Oct 1993 16:41:30 +0100
  20358. Replied: "python-list "
  20359. Received: from schelvis.cwi.nl by charon.cwi.nl with SMTP
  20360.     id AA05930 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 14:44:49 +0100
  20361. Received: by schelvis.cwi.nl with SMTP
  20362.     id AA09128 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 14:44:48 +0100
  20363. Message-Id: <9310131344.AA09128=jack@schelvis.cwi.nl>
  20364. To: Guido.van.Rossum@cwi.nl
  20365. Cc: Mark Lutz <lutz@xvt.com>, janssen@parc.xerox.com (Bill Janssen),
  20366.         python-list@cwi.nl
  20367. Subject: Re: Some python comments/questions 
  20368. In-Reply-To: Message by Guido.van.Rossum@cwi.nl ,
  20369.          Wed, 13 Oct 1993 10:28:45 +0100 , <9310130928.AA02952=guido@voorn.cwi.nl> 
  20370. Organisation: Multi-media group, CWI, Kruislaan 413, Amsterdam
  20371. Phone: +31 20 5924098(work), +31 20 5924199 (fax), +31 20 6160335(home)
  20372. X-Last-Band-Seen: Holy Rollers, Muffs (Melkweg, 2-10)
  20373. X-Mini-Review: Eventful.
  20374. Date: Wed, 13 Oct 1993 14:44:48 +0100
  20375. From: Jack Jansen <Jack.Jansen@cwi.nl>
  20376.  
  20377.  
  20378. Recently, Guido.van.Rossum@cwi.nl said:
  20379. > > Note that "f" in both functions is a local variable, so you're not 
  20380. > > really creating new symbols.  You need to "return eval('f')", instead
  20381. > > of "return f" in my python version, since "f" is not known to be a
  20382. > > local variable statically (you could also do an initial "f = None",
  20383. > > to avoid having to "eval('f')").
  20384. > This illustrates an interesting fine point of Python's eval/exec
  20385. > semantics: if exec() introduces a new name in the local namespace, the
  20386. > "compiler" can't know about it and any references to it later will
  20387. > fail mysteriously (since it actually exists in the dictionary of local
  20388. > variables but the generated pseudo code will use a "global variable
  20389. > reference" and fail to find it).
  20390.  
  20391. I often get bitten by this. Would it be possible to let eval() set
  20392. some flag or something whereby either the compiler or the runtime code
  20393. would stop accessing local variable the cheap way, but go through the
  20394. dictionary instead?
  20395. --
  20396. Jack Jansen        | If I can't dance I don't want to be part of
  20397. Jack.Jansen@cwi.nl | your revolution             -- Emma Goldman
  20398. uunet!cwi.nl!jack    G=Jack;S=Jansen;O=cwi;PRMD=surf;ADMD=400net;C=nl
  20399. 
  20400. 
  20401. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  20402.     id AA07811 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 16:19:15 +0100
  20403. To: Guido.van.Rossum@cwi.nl
  20404. Cc: Fraser@europarc.xerox.com, python-list@cwi.nl
  20405. In-Reply-To: <9310131007.AA03066=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  20406. Subject: Re: Some python comments/questions (correction) 
  20407. X-Signed: PGP-Attached-clearsig-2-3,
  20408.     iQCVAgUBLLwcK2nDnXuZ0ONVAQETlwP+O7wMbVvke41Pm5JjtHTE0wzgr4sjWHLQ
  20409.     fvrO1t6oI6hSXvvfftSdzCF/8KdwovSEttkzozREtWLQvZSKcomD3bCsJ/fBYjuA
  20410.     KP8GbhCi32x2lljyRQBUlHjlH6U1VnCeB17oKzXBsrg/u5mzhfxm3+RGHcYTW896
  20411.     3Xh/1ChR2Kc=
  20412. X-Organization: Mark V Systems Ltd.
  20413. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  20414. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  20415. Date: Wed, 13 Oct 93 8:18:11 PDT
  20416. From: lance@markv.com
  20417. Sender: lance@markv.com
  20418. Message-Id:  <9310130818.aa28778@hermix.markv.com>
  20419. Source-Info:  From (or Sender) name not authenticated.
  20420.  
  20421.  > > I have to say that I don't think the 'primes' program included in
  20422.  > > the BLURB document is a good example of Python's clarity and
  20423.  > > ease-of-use.  We need a clear bit of sample code that makes people say
  20424.  > > "Hey, this is worth downloading" when it appears on comp.sources.
  20425.  > 
  20426.  > Hmm, that is indeed a somewhat convoluted bit of code.  I think we
  20427.  > would need several short examples, highlighting different aspects of
  20428.  > the language: a simple numerical algorithm (printing Fibonacci
  20429.  > numbers?  who can think of a more interesting example?), some I/O and
  20430.  > system calls, some object-oriented stuff, some windowing (would an
  20431.  > example using Motif be a better choice than one for STDWIN?).
  20432.  
  20433.  I think an example using Motif would be a better choice. More people
  20434. will look at it and say "I could use that!". Currently a lot of people
  20435. are moving to TCL from C because of the Tk package (Motif interface
  20436. for those who don't know). If people saw how clean Python is with a 
  20437. Motif interface, I think some would drop TCL/Tk and go with Python..
  20438. Python is a MUCH cleaner language.
  20439.  
  20440. - --
  20441.  
  20442. Lance Ellinghouse           lance@markv.com
  20443.  
  20444. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  20445. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  20446. You can receive my Public Key by `finger lance@markv.com`
  20447. 
  20448. 
  20449. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  20450.     id AA08319 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 16:41:34 +0100
  20451. Received: by voorn.cwi.nl with SMTP
  20452.     id AA04116 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 16:41:31 +0100
  20453. Message-Id: <9310131541.AA04116=guido@voorn.cwi.nl>
  20454. To: python-list@cwi.nl
  20455. Subject: Re: Some python comments/questions 
  20456. In-Reply-To: Your message of "Wed, 13 Oct 1993 14:44:48 MET."
  20457.              <9310131344.AA09128=jack@schelvis.cwi.nl> 
  20458. From: Guido.van.Rossum@cwi.nl
  20459. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20460. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20461. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20462. Date: Wed, 13 Oct 1993 16:41:30 +0100
  20463. Sender: Guido.van.Rossum@cwi.nl
  20464.  
  20465. > I often get bitten by this. Would it be possible to let eval() set
  20466. > some flag or something whereby either the compiler or the runtime code
  20467. > would stop accessing local variable the cheap way, but go through the
  20468. > dictionary instead?
  20469.  
  20470. I walked over to Jack's office to explain why this wasn't a good idea,
  20471. and in the ensueing discussion we suddenly came up with the following
  20472. solution: make exec a statement instead of a function.  The syntax
  20473. would be
  20474.  
  20475.     exec <expression> [in <expression> [, <expression>]]
  20476.  
  20477. and the compiler can switch off any optimizations for functions
  20478. containing exec statements.  There is a precedent for this: the same
  20479. happens when the compiler sees "from <module> import *", because it
  20480. can't tell what local variables the star will introduce.
  20481.  
  20482. The change will break some existing Python code: statements calling
  20483. exec() with an explicit global and/or local dictionary.  The majority
  20484. of exec() function calls will still work since the extra parentheses
  20485. are harmless.
  20486.  
  20487. How about it?
  20488.  
  20489. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20490. 
  20491. 
  20492. To: python-list
  20493. Subject: Re: Some python comments/questions 
  20494. In-reply-to: Your message of "Wed, 13 Oct 1993 14:44:48 MET."
  20495.              <9310131344.AA09128=jack@schelvis.cwi.nl> 
  20496. From: Guido.van.Rossum@cwi.nl
  20497. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20498. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20499. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20500. Date: Wed, 13 Oct 1993 16:41:30 +0100
  20501. Sender: guido
  20502.  
  20503. > I often get bitten by this. Would it be possible to let eval() set
  20504. > some flag or something whereby either the compiler or the runtime code
  20505. > would stop accessing local variable the cheap way, but go through the
  20506. > dictionary instead?
  20507.  
  20508. I walked over to Jack's office to explain why this wasn't a good idea,
  20509. and in the ensueing discussion we suddenly came up with the following
  20510. solution: make exec a statement instead of a function.  The syntax
  20511. would be
  20512.  
  20513.     exec <expression> [in <expression> [, <expression>]]
  20514.  
  20515. and the compiler can switch off any optimizations for functions
  20516. containing exec statements.  There is a precedent for this: the same
  20517. happens when the compiler sees "from <module> import *", because it
  20518. can't tell what local variables the star will introduce.
  20519.  
  20520. The change will break some existing Python code: statements calling
  20521. exec() with an explicit global and/or local dictionary.  The majority
  20522. of exec() function calls will still work since the extra parentheses
  20523. are harmless.
  20524.  
  20525. How about it?
  20526.  
  20527. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20528. 
  20529. 
  20530. Received: from sapling.surfnet.nl by charon.cwi.nl with SMTP
  20531.     id AA08972 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 17:08:57 +0100
  20532. X400-Received: by mta sapling.surfnet.nl in /PRMD=surf/ADMD=400net/C=nl/;
  20533.                Relayed; Wed, 13 Oct 1993 17:08:56 +0100
  20534. X400-Received: by /PRMD=uk.ac/ADMD= /C=gb/; Relayed;
  20535.                Wed, 13 Oct 1993 17:07:45 +0100
  20536. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  20537.                Wed, 13 Oct 1993 17:07:16 +0100
  20538. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  20539.                Wed, 13 Oct 1993 17:03:56 +0100
  20540. X400-Received: by /PRMD=UK.AC/ADMD= /C=GB/; Relayed;
  20541.                Wed, 13 Oct 1993 17:03:56 +0100
  20542. Date: Wed, 13 Oct 1993 17:03:56 +0100
  20543. X400-Originator: peter%robots.oxford.ac.uk@prg.oxford.ac.uk
  20544. X400-Recipients: python-list@cwi.nl
  20545. X400-Mts-Identifier: [/PRMD=UK.AC/ADMD= /C=GB/;<9310131603.AA20864@quickly.robo]
  20546. X400-Content-Type: P2-1984 (2)
  20547. Content-Identifier: Re: Some pyth...
  20548. From: peter@robots.oxford.ac.uk
  20549. Message-Id: <9310131603.AA20864@quickly.robots.ox.ac.uk>
  20550. To: python-list@cwi.nl
  20551. Subject: Re: Some python comments/questions (correction)
  20552.  
  20553. > From lance@markv.com Wed Oct 13 16:23:08 1993
  20554. >  I think an example using Motif would be a better choice. More people
  20555. > will look at it and say "I could use that!". Currently a lot of people
  20556. > are moving to TCL from C because of the Tk package (Motif interface
  20557. > for those who don't know). If people saw how clean Python is with a 
  20558. > Motif interface, I think some would drop TCL/Tk and go with Python..
  20559. > Python is a MUCH cleaner language.
  20560.  
  20561. What about a python interface to tk?  Has anyone done it?
  20562.  
  20563. Pete.
  20564. 
  20565. 
  20566. Replied: Wed, 13 Oct 1993 21:34:13 +0100
  20567. Replied: "lance@markv.com python-list"
  20568. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  20569.     id AA09117 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 17:16:42 +0100
  20570. To: Guido.van.Rossum@cwi.nl
  20571. Cc: python-list@cwi.nl
  20572. In-Reply-To: <9310131541.AA04116=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  20573. Subject: Re: Some python comments/questions 
  20574. X-Organization: Mark V Systems Ltd.
  20575. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  20576. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  20577. Date: Wed, 13 Oct 93 9:15:47 PDT
  20578. From: lance@markv.com
  20579. Sender: lance@markv.com
  20580. Message-Id:  <9310130915.aa04945@hermix.markv.com>
  20581. Source-Info:  From (or Sender) name not authenticated.
  20582.  
  20583.  > > I often get bitten by this. Would it be possible to let eval() set
  20584.  > > some flag or something whereby either the compiler or the runtime code
  20585.  > > would stop accessing local variable the cheap way, but go through the
  20586.  > > dictionary instead?
  20587.  > 
  20588.  > I walked over to Jack's office to explain why this wasn't a good idea,
  20589.  > and in the ensueing discussion we suddenly came up with the following
  20590.  > solution: make exec a statement instead of a function.  The syntax
  20591.  > would be
  20592.  > 
  20593.  >     exec <expression> [in <expression> [, <expression>]]
  20594.  > 
  20595.  > and the compiler can switch off any optimizations for functions
  20596.  > containing exec statements.  There is a precedent for this: the same
  20597.  > happens when the compiler sees "from <module> import *", because it
  20598.  > can't tell what local variables the star will introduce.
  20599.  > 
  20600.  > The change will break some existing Python code: statements calling
  20601.  > exec() with an explicit global and/or local dictionary.  The majority
  20602.  > of exec() function calls will still work since the extra parentheses
  20603.  > are harmless.
  20604.  > 
  20605.  > How about it?
  20606.  
  20607.  PLEASE DON'T!!!!! I have a bunch of code that relies on passing in
  20608. explicit local and global dictionaries!!
  20609.  
  20610. My code does the following:
  20611.  
  20612.    co = code object loaded from a file using marshal.load()
  20613.    l_ns = {}
  20614.    exec(co,{},l_ns)
  20615.    exec(co,l_ns,l_ns)
  20616.  
  20617. I then call functions as:
  20618.  
  20619.    l_ns['function_name'](args)
  20620.  
  20621. Each l_ns is a completely seperate name space and seperate environment!
  20622. I need this! Please don't take it away! Or tell me a better way to do it.
  20623.  
  20624. --
  20625.  
  20626. Lance Ellinghouse           lance@markv.com
  20627.  
  20628. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  20629. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  20630. You can receive my Public Key by `finger lance@markv.com`
  20631. 
  20632. 
  20633. Replied: Wed, 13 Oct 1993 21:21:45 +0100
  20634. Replied: "Mark Lutz <lutz@xvt.com> "
  20635. Received: from csn.org by charon.cwi.nl with SMTP
  20636.     id AA09738 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 17:40:07 +0100
  20637. Received: by csn.org with UUCP id AA06557
  20638.   (5.65c/IDA-1.4.4 for python-list@cwi.nl); Wed, 13 Oct 1993 10:38:46 -0600
  20639. Received: by zeus.xvt.com id AA00984
  20640.   (5.65c/IDA-1.4.4); Wed, 13 Oct 1993 10:30:34 -0600
  20641. From: Mark Lutz <lutz@xvt.com>
  20642. Message-Id: <199310131630.AA00984@zeus.xvt.com>
  20643. Subject: Re: Some python comments/questions (correction)
  20644. To: Fraser@europarc.xerox.com (Quentin Stafford-Fraser)
  20645. Date: Wed, 13 Oct 93 10:30:33 MDT
  20646. Cc: python-list@cwi.nl
  20647. In-Reply-To: <199310130924.AA28934@eros.EuroPARC.Xerox.COM>; from "Quentin Stafford-Fraser" at Oct 13, 93 2:24 am
  20648.  
  20649. > I have to say that I don't think the 'primes' program included in the BLURB document is a good example of Python's clarity and ease-of-use.  We need a clear bit of sample code that makes people say "Hey, this is worth downloading" when it appears on comp.> sources.
  20650. > Anybody like to volunteer some?
  20651.  
  20652. I've written a forward/backward chaining expert system shell in Python
  20653. which is a bit long (multiple modules), but demonstrates using Python
  20654. for serious development (and something you'd have to be insane to try 
  20655. in Perl/TCL/etc...).  I'd be happy to donate the code if appropriate.
  20656.  
  20657. Mark Lutz
  20658. lutz@xvt.com
  20659. 
  20660. 
  20661. Received: from quark.phys.washington.edu by charon.cwi.nl with SMTP
  20662.     id AA11053 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 18:05:04 +0100
  20663. Received: by quark.phys.washington.edu
  20664.     (5.65/UW-NDC Revision: 2.25 ) id AA02440; Wed, 13 Oct 93 10:05:01 -0700
  20665. Date: Wed, 13 Oct 1993 09:59:47 -0700 (PDT)
  20666. From: Jon Eisenberg <jke@u.washington.edu>
  20667. Subject: Re: Some python comments/questions 
  20668. To: Guido.van.Rossum@cwi.nl
  20669. In-Reply-To: <9310131541.AA04116=guido@voorn.cwi.nl>
  20670. Message-Id: <Pine.3.07.9310130945.A2300-b100000@quark.phys.washington.edu>
  20671. Mime-Version: 1.0
  20672. Content-Type: TEXT/PLAIN; charset=US-ASCII
  20673.  
  20674. On Wed, 13 Oct 1993 Guido.van.Rossum@cwi.nl wrote:
  20675. > The change will break some existing Python code: statements calling
  20676. > exec() with an explicit global and/or local dictionary.  The majority
  20677. > of exec() function calls will still work since the extra parentheses
  20678. > are harmless.
  20679. > How about it?
  20680. > --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20681. I am developing a data analysis application using python as the interface
  20682. and user programming language.  Your proposed change in exec would seem to
  20683. break it.
  20684.  
  20685. I use the feature of passing an explicit dictionary for the following
  20686. reason.  I have a database with named entries on which I wish to perform
  20687. calculations. To evaluate an expression of the variables names, I create
  20688. an object with features named as the database entries are (by taking an
  20689. empty class and adding the features to it), then pass the objects
  20690. dictionary as the local namespace to the exec() call.  That way I don't
  20691. have to parse the expression or clutter the local name space with
  20692. variables of the same name as the db entries.  How could I accomplish the
  20693. same after your proposed changes?
  20694.             --Jon
  20695.  
  20696. --
  20697. Jon Eisenberg
  20698. High Energy Physics Lab            e-mail:    jke@u.washington.edu
  20699. Physics Dept., FM-15                            (or jke@uwaphast.bitnet)
  20700. Univ. of Washington                phone:       206-543-6886  office
  20701. Seattle, WA 98195                  fax:         206-685-0635 
  20702.  
  20703. 
  20704. 
  20705. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  20706.     id AA11535 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 18:34:29 +0100
  20707. To: peter@robots.ox.ac.uk
  20708. Cc: python-list@cwi.nl
  20709. In-Reply-To: <9310131603.AA20864@quickly.robots.ox.ac.uk> (peter@robots.ox.ac.uk)
  20710. Subject: Re: Some python comments/questions (correction)
  20711. X-Organization: Mark V Systems Ltd.
  20712. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  20713. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  20714. Date: Wed, 13 Oct 93 10:33:41 PDT
  20715. From: lance@markv.com
  20716. Sender: lance@markv.com
  20717. Message-Id:  <9310131033.aa12989@hermix.markv.com>
  20718. Source-Info:  From (or Sender) name not authenticated.
  20719.  
  20720.  > > From lance@markv.com Wed Oct 13 16:23:08 1993
  20721.  > >  I think an example using Motif would be a better choice. More people
  20722.  > > will look at it and say "I could use that!". Currently a lot of people
  20723.  > > are moving to TCL from C because of the Tk package (Motif interface
  20724.  > > for those who don't know). If people saw how clean Python is with a 
  20725.  > > Motif interface, I think some would drop TCL/Tk and go with Python..
  20726.  > > Python is a MUCH cleaner language.
  20727.  > 
  20728.  > What about a python interface to tk?  Has anyone done it?
  20729.  
  20730.  Why bother? the Motif interface that comes wih Python 0.9.9 is
  20731. much cleaner than tk will ever be!
  20732.  
  20733. --
  20734.  
  20735. Lance Ellinghouse           lance@markv.com
  20736.  
  20737. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  20738. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  20739. You can receive my Public Key by `finger lance@markv.com`
  20740. 
  20741. 
  20742. Received: from ohmg.hydro.on.ca by charon.cwi.nl with SMTP
  20743.     id AA12098 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 19:15:07 +0100
  20744. Received: from eagle.hydro.on.ca by ohmg.hydro.on.ca with SMTP id <67324>; Wed, 13 Oct 1993 14:37:41 -0400
  20745. Received: by eagle.hydro.on.ca (4.1/SMI-4.1)
  20746.     id AA20512; Wed, 13 Oct 93 14:09:49 EDT
  20747. Received: from thor.rd.hydro.on.ca by ohrd.rd.hydro.on.ca with SMTP id AA25586
  20748.   (5.65c/IDA-1.4.4 for python-list@cwi.nl); Wed, 13 Oct 1993 14:14:37 -0400
  20749. Received: by thor.rd.hydro.on.ca id AA15275
  20750.   (5.65c/IDA-1.4.4 for python-list@cwi.nl); Wed, 13 Oct 1993 14:16:42 -0400
  20751. Date:     Wed, 13 Oct 1993 14:16:42 -0400
  20752. From: Martin Green <martin.a.green@hydro.on.ca>
  20753. Message-Id: <199310131816.AA15275@thor.rd.hydro.on.ca>
  20754. To: python-list@cwi.nl
  20755. Subject: Re: Some python comments/questions (correction)
  20756. In-Reply-To: <9310131603.AA20864@quickly.robots.ox.ac.uk>
  20757. References: <9310131603.AA20864@quickly.robots.ox.ac.uk>
  20758.  
  20759. On October 13 at 12:03:56 peter@robots.ox.ac.uk wrote:
  20760.  > > From lance@markv.com Wed Oct 13 16:23:08 1993
  20761.  > >  I think an example using Motif would be a better choice. More people
  20762.  > > will look at it and say "I could use that!". Currently a lot of people
  20763.  > > are moving to TCL from C because of the Tk package (Motif interface
  20764.  > > for those who don't know). If people saw how clean Python is with a 
  20765.  > > Motif interface, I think some would drop TCL/Tk and go with Python..
  20766.  > > Python is a MUCH cleaner language.
  20767.  > 
  20768.  > What about a python interface to tk?  Has anyone done it?
  20769.  > 
  20770. I raised this with Guido and John Ousterhout (author of TCL/Tk)
  20771. several months ago, and even agreed to do it if I could find the time.
  20772. Although I have been following this list with great interest, I have
  20773. been too busy working on a project using TCL to properly learn Python,
  20774. or take on the Tk project.  Its a chicken and egg situation :-(.
  20775.  
  20776. Tk is a terrific system that looks like, but is distinct from, Motif.
  20777. It relies heavily on the TCL interpreter, so adding Tk support to
  20778. Python also means adding TCL.  It would probably be easiest to add a
  20779. Python interpreter to Tk's windowing shell (wish), rather than adding
  20780. TCL/Tk to Python.
  20781.  
  20782. Martin A. Green                     Net :  green@rd.hydro.on.ca
  20783. Ontario Hydro Technologies          Tel :  (416) 207-5745
  20784. 800 Kipling Ave,  KR260             FAX :  (416) 207-5622
  20785. Toronto, Ontario, CANADA, M8Z5S4
  20786. 
  20787. 
  20788. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  20789.     id AA13988 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 21:34:14 +0100
  20790. Received: by voorn.cwi.nl with SMTP
  20791.     id AA04541 (5.65b/3.8/CWI-Amsterdam); Wed, 13 Oct 1993 21:34:13 +0100
  20792. Message-Id: <9310132034.AA04541=guido@voorn.cwi.nl>
  20793. To: lance@markv.com
  20794. Cc: python-list@cwi.nl
  20795. Subject: Re: Some python comments/questions 
  20796. In-Reply-To: Your message of "Wed, 13 Oct 1993 09:15:47 MDT."
  20797.              <9310130915.aa04945@hermix.markv.com> 
  20798. From: Guido.van.Rossum@cwi.nl
  20799. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20800. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20801. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20802. Date: Wed, 13 Oct 1993 21:34:13 +0100
  20803. Sender: Guido.van.Rossum@cwi.nl
  20804.  
  20805. Lance Ellinghouse:
  20806. >  PLEASE DON'T!!!!! I have a bunch of code that relies on passing in
  20807. > explicit local and global dictionaries!!
  20808.  
  20809. and Jon Eisberg:
  20810. > I am developing a data analysis application using python as the interface
  20811. > and user programming language.  Your proposed change in exec would seem to
  20812. > break it.
  20813.  
  20814. Sorry folks, that's not what I meant to say!  Your functionality will
  20815. of course still be supported.  Here's my proposed syntax again:
  20816.  
  20817.      exec <expression> [in <expression> [, <expression>]]
  20818.  
  20819. The optional "in ..." part would be used to pass the global/local
  20820. dictionary as with the current exec() function (and using this
  20821. feature would mean the compiler did not have to stop optimizing
  20822. locals).  My remark that the change would "break" existing code was
  20823. meant to apply at the syntactic level -- you will have to change all
  20824. your lines that currently read
  20825.  
  20826.     exec(a, b, c)
  20827.  
  20828. into
  20829.  
  20830.     exec a in b, c
  20831.  
  20832. (and I will even make a script that does this painlessly, just as for
  20833. other incompatible syntax changes in the past).
  20834.  
  20835. Sorry about the confusion,
  20836.  
  20837. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20838. 
  20839. 
  20840. To: lance@markv.com
  20841. cc: python-list
  20842. Subject: Re: Some python comments/questions 
  20843. In-reply-to: Your message of "Wed, 13 Oct 1993 09:15:47 MDT."
  20844.              <9310130915.aa04945@hermix.markv.com> 
  20845. From: Guido.van.Rossum@cwi.nl
  20846. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  20847. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  20848. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  20849. Date: Wed, 13 Oct 1993 21:34:13 +0100
  20850. Sender: guido
  20851.  
  20852. Lance Ellinghouse:
  20853. >  PLEASE DON'T!!!!! I have a bunch of code that relies on passing in
  20854. > explicit local and global dictionaries!!
  20855.  
  20856. and Jon Eisberg:
  20857. > I am developing a data analysis application using python as the interface
  20858. > and user programming language.  Your proposed change in exec would seem to
  20859. > break it.
  20860.  
  20861. Sorry folks, that's not what I meant to say!  Your functionality will
  20862. of course still be supported.  Here's my proposed syntax again:
  20863.  
  20864.      exec <expression> [in <expression> [, <expression>]]
  20865.  
  20866. The optional "in ..." part would be used to pass the global/local
  20867. dictionary as with the current exec() function (and using this
  20868. feature would mean the compiler did not have to stop optimizing
  20869. locals).  My remark that the change would "break" existing code was
  20870. meant to apply at the syntactic level -- you will have to change all
  20871. your lines that currently read
  20872.  
  20873.     exec(a, b, c)
  20874.  
  20875. into
  20876.  
  20877.     exec a in b, c
  20878.  
  20879. (and I will even make a script that does this painlessly, just as for
  20880. other incompatible syntax changes in the past).
  20881.  
  20882. Sorry about the confusion,
  20883.  
  20884. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  20885. 
  20886. 
  20887. Replied: Wed, 13 Oct 1993 22:42:24 +0100
  20888. Replied: "Bill Janssen <janssen@parc.xerox.com> "
  20889. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  20890.     id AA14079 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 21:42:44 +0100
  20891. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12209>; Wed, 13 Oct 1993 13:42:24 PDT
  20892. Received: by holmes.parc.xerox.com id <16134>; Wed, 13 Oct 1993 13:42:21 -0700
  20893. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  20894.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  20895.           Wed, 13 Oct 1993 13:42:11 -0700 (PDT)
  20896. Message-Id: <Egj6UXwB0KGW9Dk4lJ@holmes.parc.xerox.com>
  20897. Date:     Wed, 13 Oct 1993 13:42:11 PDT
  20898. Sender: Bill Janssen <janssen@parc.xerox.com>
  20899. From: Bill Janssen <janssen@parc.xerox.com>
  20900. To: Bill Janssen <janssen@parc.xerox.com>, Guido.van.Rossum@cwi.nl
  20901. Subject: Re: Python and UI
  20902. Cc: python-list@cwi.nl
  20903. In-Reply-To: <9310130957.AA03031=guido@voorn.cwi.nl>
  20904. References: <9310130957.AA03031=guido@voorn.cwi.nl>
  20905.  
  20906. Excerpts from direct: 13-Oct-93 Re: Python and UI Guido.van.Rossum@cwi.nl (821)
  20907.  
  20908. > I like
  20909. > what SUIT does for simple interfaces but am not convinced that it can
  20910. > replace STDWIN -- I seem to remember that you always get exactly one
  20911. > top-level window, and I don't recollect there being a non-X11 version.
  20912.  
  20913. It's layered on top of srgp, so it should work on the Mac as well (srgp
  20914. is very much like STDWIN, and has ports to the Mac and X11).  But I
  20915. don't think there's an MS-Windows port...
  20916.  
  20917. Is there any way to create an STDWIN window without the menubar?
  20918.  
  20919. Bill
  20920.  
  20921. 
  20922. 
  20923. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  20924.     id AA14163 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 21:53:36 +0100
  20925. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12212>; Wed, 13 Oct 1993 13:53:15 PDT
  20926. Received: by holmes.parc.xerox.com id <16134>; Wed, 13 Oct 1993 13:53:07 -0700
  20927. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  20928.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  20929.           Wed, 13 Oct 1993 13:52:57 -0700 (PDT)
  20930. Message-Id: <ogj6edcB0KGWRDk5x3@holmes.parc.xerox.com>
  20931. Date:     Wed, 13 Oct 1993 13:52:57 PDT
  20932. Sender: Bill Janssen <janssen@parc.xerox.com>
  20933. From: Bill Janssen <janssen@parc.xerox.com>
  20934. To: Guido.van.Rossum@cwi.nl
  20935. Subject: Re: Some python comments/questions (correction)
  20936. Cc: python-list@cwi.nl
  20937. In-Reply-To: <9310131007.AA03066=guido@voorn.cwi.nl>
  20938. References: <9310131007.AA03066=guido@voorn.cwi.nl>
  20939.  
  20940. Excerpts from mail: 13-Oct-93 Re: Some python comments/qu..
  20941. Guido.van.Rossum@cwi.nl (1438)
  20942.  
  20943. > some windowing (would an
  20944. > example using Motif be a better choice than one for STDWIN?).
  20945.  
  20946. Of course you need the shortest possible hello, world; something like:
  20947.  
  20948.     #! /usr/local/bin/python
  20949.  
  20950.     import stdwin
  20951.     stdwin.message('Hello, World!')
  20952.  
  20953. Bill
  20954. 
  20955. 
  20956. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  20957.     id AA14198 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 21:56:02 +0100
  20958. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12214>; Wed, 13 Oct 1993 13:55:46 PDT
  20959. Received: by holmes.parc.xerox.com id <16134>; Wed, 13 Oct 1993 13:55:38 -0700
  20960. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  20961.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  20962.           Wed, 13 Oct 1993 13:55:28 -0700 (PDT)
  20963. Message-Id: <wgj6h0YB0KGWJDk6Vw@holmes.parc.xerox.com>
  20964. Date:     Wed, 13 Oct 1993 13:55:28 PDT
  20965. Sender: Bill Janssen <janssen@parc.xerox.com>
  20966. From: Bill Janssen <janssen@parc.xerox.com>
  20967. To: Guido.van.Rossum@cwi.nl
  20968. Subject: Re: Some python comments/questions
  20969. Cc: python-list@cwi.nl
  20970. In-Reply-To: <9310131541.AA04116=guido@voorn.cwi.nl>
  20971. References: <9310131541.AA04116=guido@voorn.cwi.nl>
  20972.  
  20973. Excerpts from mail: 13-Oct-93 Re: Some python comments/qu..
  20974. Guido.van.Rossum@cwi.nl (1068)
  20975.  
  20976. > The change will break some existing Python code: statements calling
  20977. > exec() with an explicit global and/or local dictionary.  The majority
  20978. > of exec() function calls will still work since the extra parentheses
  20979. > are harmless.
  20980.  
  20981. Hmmm.  I was sort of counting on having this continue to work.
  20982.  
  20983. Bill
  20984.  
  20985. 
  20986. 
  20987. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  20988.     id AA14485 (5.65b/3.11/CWI-Amsterdam); Wed, 13 Oct 1993 22:19:28 +0100
  20989. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  20990.     id AA08285; Wed, 13 Oct 1993 17:19:05 -0400
  20991. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  20992.     id AA05311; Wed, 13 Oct 93 17:19:39 EDT
  20993. Received: by kaos.ksr.com (4.1/KSR-2.0)
  20994.     id AA29372; Wed, 13 Oct 93 17:19:37 EDT
  20995. Message-Id: <9310132119.AA29372@kaos.ksr.com>
  20996. To: Guido.van.Rossum@cwi.nl
  20997. Subject: Python examples (was Re: Some python comments/questions (correction))
  20998. Cc: python-list@cwi.nl
  20999. Date: Wed, 13 Oct 93 17:19:36 -0400
  21000. From: Tim Peters <tim@ksr.com>
  21001.  
  21002. > ... a simple numerical algorithm (printing Fibonacci numbers?  who can
  21003. > think of a more interesting example?), ...
  21004.  
  21005. How about this piece?  It's a useful algorithm that manages to illustrate
  21006. lots of things interesting to number-crunchers:  long ints, short ints,
  21007. floats, implicit & explicit coercions, useful builtin functions, multiple
  21008. assignment, simple import, painless quick output, & multi-valued
  21009. functions:
  21010.  
  21011. print 'approximations to pi'
  21012.  
  21013. import math
  21014. top    = 31415926535897932385L
  21015. bottom = 10000000000000000000L
  21016. p2, p1 = 0, 1
  21017. q2, q1 = 1, 0
  21018.  
  21019. while q1 < 1000000:
  21020.     quotient, remainder = divmod( top, bottom )
  21021.     p2, p1 = p1, p2 + quotient * p1
  21022.     q2, q1 = q1, q2 + quotient * q1
  21023.     top, bottom = bottom, remainder
  21024.  
  21025.     diff = float(p1)/q1 - math.pi
  21026.     sign = '+'
  21027.     if diff < 0: sign = '-'
  21028.     print p1, '/', q1, '\t= pi', sign, abs(diff)
  21029.  
  21030. It also illustrates that floating-point output may differ on different
  21031. machines, which gives every number-cruncher that warm glow of easy
  21032. familiarity <grin>:
  21033.  
  21034. approximations to pi
  21035. 3L / 1L         = pi - 0.14159265359
  21036. 22L / 7L        = pi + 0.00126448926735
  21037. 333L / 106L     = pi - 8.32196275291e-05
  21038. 355L / 113L     = pi + 2.66764189405e-07
  21039. 103993L / 33102L        = pi - 5.77890624243e-10
  21040. 104348L / 33215L        = pi + 3.31628058348e-10
  21041. 208341L / 66317L        = pi - 1.22356347276e-10
  21042. 312689L / 99532L        = pi + 2.91433543964e-11
  21043. 833719L / 265381L       = pi - 8.71525074331e-12
  21044. 1146408L / 364913L      = pi + 1.61071156413e-12
  21045. 4272943L / 1360120L     = pi - 4.04121180964e-13
  21046.  
  21047. > ... but for those who are afraid of Perl it might actually work to
  21048. > compare a few cases of Python and Perl code...
  21049.  
  21050. Perhaps more to the point, if you include _any_ comparison of Python &
  21051. Perl, it will guarantee a flame war that will keep Python's name active
  21052. on the Net for months <snicker> ...
  21053.  
  21054. good-publicity-bad-publicity-just-so-long-as-they-spell-the-name-right-ly
  21055.    y'rs  - tim
  21056.  
  21057. Tim Peters   tim@ksr.com
  21058. not speaking for Kendall Square Research Corp
  21059. 
  21060. 
  21061. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  21062.     id AA16087 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 00:30:45 +0100
  21063. To: Guido.van.Rossum@cwi.nl
  21064. Cc: python-list@cwi.nl
  21065. In-Reply-To: <9310132034.AA04541=guido@voorn.cwi.nl> (Guido.van.Rossum@cwi.nl)
  21066. Subject: Re: Some python comments/questions 
  21067. X-Organization: Mark V Systems Ltd.
  21068. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  21069. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  21070. Date: Wed, 13 Oct 93 16:29:37 PDT
  21071. From: lance@markv.com
  21072. Sender: lance@markv.com
  21073. Message-Id:  <9310131629.aa14070@hermix.markv.com>
  21074. Source-Info:  From (or Sender) name not authenticated.
  21075.  
  21076.  > From charon.cwi.nl!cwi.nl!guido Wed Oct 13 13:38:25 1993
  21077.  > Cc: python-list@cwi.nl
  21078.  > From: Guido.van.Rossum@cwi.nl
  21079.  > X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  21080.  > X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  21081.  > X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  21082.  > Date: Wed, 13 Oct 1993 21:34:13 +0100
  21083.  > Sender: Guido.van.Rossum@cwi.nl
  21084.  > 
  21085.  > Lance Ellinghouse:
  21086.  > >  PLEASE DON'T!!!!! I have a bunch of code that relies on passing in
  21087.  > > explicit local and global dictionaries!!
  21088.  > 
  21089.  > and Jon Eisberg:
  21090.  > > I am developing a data analysis application using python as the interface
  21091.  > > and user programming language.  Your proposed change in exec would seem to
  21092.  > > break it.
  21093.  > 
  21094.  > Sorry folks, that's not what I meant to say!  Your functionality will
  21095.  > of course still be supported.  Here's my proposed syntax again:
  21096.  > 
  21097.  >      exec <expression> [in <expression> [, <expression>]]
  21098.  > 
  21099.  > The optional "in ..." part would be used to pass the global/local
  21100.  > dictionary as with the current exec() function (and using this
  21101.  > feature would mean the compiler did not have to stop optimizing
  21102.  > locals).  My remark that the change would "break" existing code was
  21103.  > meant to apply at the syntactic level -- you will have to change all
  21104.  > your lines that currently read
  21105.  > 
  21106.  >     exec(a, b, c)
  21107.  > 
  21108.  > into
  21109.  > 
  21110.  >     exec a in b, c
  21111.  > 
  21112.  > (and I will even make a script that does this painlessly, just as for
  21113.  > other incompatible syntax changes in the past).
  21114.  > 
  21115.  > Sorry about the confusion,
  21116.  
  21117.  That is a relief!
  21118.  
  21119. --
  21120.  
  21121. Lance Ellinghouse           lance@markv.com
  21122.  
  21123. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  21124. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  21125. You can receive my Public Key by `finger lance@markv.com`
  21126. 
  21127. 
  21128. Replied: Thu, 14 Oct 1993 11:17:14 +0100
  21129. Replied: "lance@markv.com "
  21130. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  21131.     id AA16125 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 00:38:08 +0100
  21132. To: python-list@cwi.nl
  21133. Subject: current 'index' file for python FTP site
  21134. X-Organization: Mark V Systems Ltd.
  21135. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  21136. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  21137. Date: Wed, 13 Oct 93 16:37:26 PDT
  21138. From: lance@markv.com
  21139. Sender: lance@markv.com
  21140. Message-Id:  <9310131637.aa15147@hermix.markv.com>
  21141. Source-Info:  From (or Sender) name not authenticated.
  21142.  
  21143.  
  21144. Well I FINALLY have a single file in the FTP site I am maintaining
  21145. for python .py files and stuff like that..
  21146.  
  21147. Here is the current 'index' file.. If you can think of a better format, 
  21148. PLEASE let me know what you prefer.. and I will see about putting it
  21149. together..
  21150.  
  21151. ------ Cut
  21152. Index of ftp.markv.com:/pub/python
  21153.  
  21154. Files:
  21155.     Dates.py
  21156.     Dates.readme
  21157. Author:
  21158.     Tim Peters <tim@ksr.com>
  21159. Description:
  21160.     Date manipulation class
  21161.     See Dates.readme and Dates.py for more info..
  21162.  
  21163.  
  21164.  
  21165.  
  21166.  
  21167. --
  21168.  
  21169. Lance Ellinghouse           lance@markv.com
  21170.  
  21171. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  21172. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  21173. You can receive my Public Key by `finger lance@markv.com`
  21174. 
  21175. 
  21176. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  21177.     id AA16690 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 01:37:33 +0100
  21178. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12293>; Wed, 13 Oct 1993 17:33:31 PDT
  21179. Received: by holmes.parc.xerox.com id <16134>; Wed, 13 Oct 1993 17:33:19 -0700
  21180. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  21181.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  21182.           Wed, 13 Oct 1993 17:33:12 -0700 (PDT)
  21183. Message-Id: <0gj9t8kB0KGWFDk75a@holmes.parc.xerox.com>
  21184. Date:     Wed, 13 Oct 1993 17:33:12 PDT
  21185. Sender: Bill Janssen <janssen@parc.xerox.com>
  21186. From: Bill Janssen <janssen@parc.xerox.com>
  21187. To: lance@markv.com
  21188. Subject: More on Python and UI
  21189. Cc: python-list@cwi.nl
  21190. In-Reply-To: <9310131033.aa12989@hermix.markv.com>
  21191. References: <9310131033.aa12989@hermix.markv.com>
  21192.  
  21193. Excerpts from mail: 13-Oct-93 Re: Some python comments/qu..
  21194. lance@markv.com (889)
  21195.  
  21196. >  Why bother? the Motif interface that comes wih Python 0.9.9 is
  21197. > much cleaner than tk will ever be!
  21198.  
  21199. It also bloats python from 1MB to 3MB on the Sun, making it
  21200. realistically unusable for quick small programs.  What Tk has going for
  21201. it (with Tcl), is that it is quick and small -- it doesn't require the
  21202. Motif library to be linked in.  I think, though, that we could come up
  21203. with something *much* better than Tk, with more functionality, of
  21204. equivalent size and speed.  STDWIN is, in some ways, a good start.  What
  21205. it could use (from my limited experience with it):
  21206.  
  21207. 1)  a nice Motif-appearance set of widgets, implemented in Python or C,
  21208. to go on top of it.  (A C implementation would be analogous to Tk.)
  21209. 2)  better (faster) access to the text buffer maintained by the textedit
  21210. widget.
  21211.  
  21212. The style proposed by EZD would be a nice way to go, as well, and might
  21213. be easy to map on top of STDWIN (which would mean a 3 layer system: 
  21214. STDWIN on the bottom, "pezd" on top of that, some widget collection on
  21215. top of that).  In EZD, things are done in terms of "graphical objects"
  21216. (lines, arcs, polygons, text), which can be created and arranged without
  21217. regard to whether or not any windows actually exist.  Groups of
  21218. graphical objects are called "drawings".  Graphical objects can be bound
  21219. into drawings, and their position and stacking order controlled. 
  21220. Drawings can also then be mapped into "windows".  Multiple drawings can
  21221. be mapped into any window.  A drawing may be mapped into more than one
  21222. window.  Optional clipping rects may be defined for each binding of a
  21223. drawing to a window.  Each window can define its own coordinate space. 
  21224. Events like mouse clicks or keystrokes are mapped by EZD to the drawing
  21225. object on which the event occurred.  Redraws are done via callbacks
  21226. bound to the drawing objects.  Each drawing object uses a set of
  21227. graphical primitives similar to those used in STDWIN.  I'd have to
  21228. re-read the technical report
  21229. (ftp://gatekeeper.dec.com/pub/DEC/ezd/techreport.psf.Z) to be more
  21230. accurate than that.
  21231.  
  21232. Bill
  21233. 
  21234. 
  21235. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  21236.     id AA16712 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 01:40:43 +0100
  21237. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12297>; Wed, 13 Oct 1993 17:39:01 PDT
  21238. Received: by holmes.parc.xerox.com id <16134>; Wed, 13 Oct 1993 17:38:50 -0700
  21239. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  21240.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  21241.           Wed, 13 Oct 1993 17:38:38 -0700 (PDT)
  21242. Message-Id: <wgj9yCwB0KGWFDk7Z=@holmes.parc.xerox.com>
  21243. Date:     Wed, 13 Oct 1993 17:38:38 PDT
  21244. Sender: Bill Janssen <janssen@parc.xerox.com>
  21245. From: Bill Janssen <janssen@parc.xerox.com>
  21246. To: python-list@cwi.nl, Martin Green <martin.a.green@hydro.on.ca>
  21247. Subject: Re: Some python comments/questions (correction)
  21248. In-Reply-To: <199310131816.AA15275@thor.rd.hydro.on.ca>
  21249. References: <9310131603.AA20864@quickly.robots.ox.ac.uk>
  21250.     <199310131816.AA15275@thor.rd.hydro.on.ca>
  21251.  
  21252. Excerpts from mail: 13-Oct-93 Re: Some python comments/qu.. Martin
  21253. Green@hydro.on.ca (1436)
  21254.  
  21255. > Tk is a terrific system that looks like, but is distinct from, Motif.
  21256. > It relies heavily on the TCL interpreter, so adding Tk support to
  21257. > Python also means adding TCL.
  21258.  
  21259. Just say no.
  21260.  
  21261. Bill
  21262. 
  21263. 
  21264. Replied: Thu, 14 Oct 1993 17:25:06 +0100
  21265. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> "
  21266. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  21267.     id AA29632 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 17:21:51 +0100
  21268. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa15187;
  21269.           14 Oct 93 12:21 EDT
  21270. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  21271.     id AA13403; Thu, 14 Oct 1993 12:21:36 -0400
  21272. Date: Thu, 14 Oct 1993 12:21:36 -0400
  21273. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  21274. Message-Id: <199310141621.AA13403@elvis.med.Virginia.EDU>
  21275. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  21276. To: python-list@cwi.nl
  21277. Subject: Killed 
  21278.  
  21279.  
  21280. One of my python programs, after getting 80% into processing a 
  21281. rather large file, responds with the terse message:
  21282.  
  21283. Killed
  21284.  
  21285. and exits. 
  21286.  
  21287. That's certainly not one of MY messages. 
  21288. Maybe it's an OS message ( from IBM AIX 3.2.2 )  
  21289. Is there anyplace in the python code that might produce that message ?
  21290.  
  21291. I expect it is a cryptic message from AIX, but I thought I'ld
  21292. check to see if anyone has ever seen anything similar.
  21293.  
  21294. - Steve Majewski
  21295.  
  21296. 
  21297. 
  21298. Received: from ansjovis.cwi.nl by charon.cwi.nl with SMTP
  21299.     id AA29781 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 17:31:09 +0100
  21300. Received: by ansjovis.cwi.nl with SMTP
  21301.     id AA19051 (5.65b/3.8/CWI-Amsterdam); Thu, 14 Oct 1993 17:31:08 +0100
  21302. Message-Id: <9310141631.AA19051=sjoerd@ansjovis.cwi.nl>
  21303. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  21304. Cc: python-list@cwi.nl
  21305. Subject: Re: Killed 
  21306. In-Reply-To: Your message of Thu, 14 Oct 1993 12:21:36 -0400.
  21307.              <199310141621.AA13403@elvis.med.Virginia.EDU> 
  21308. Date: Thu, 14 Oct 1993 17:31:07 +0100
  21309. From: Sjoerd Mullender <Sjoerd.Mullender@cwi.nl>
  21310.  
  21311. On Thu, Oct 14 1993 "Steven D. Majewski" wrote:
  21312.  
  21313. > One of my python programs, after getting 80% into processing a 
  21314. > rather large file, responds with the terse message:
  21315. > Killed
  21316. > and exits. 
  21317. > That's certainly not one of MY messages. 
  21318. > Maybe it's an OS message ( from IBM AIX 3.2.2 )  
  21319. > Is there anyplace in the python code that might produce that message ?
  21320. > I expect it is a cryptic message from AIX, but I thought I'ld
  21321. > check to see if anyone has ever seen anything similar.
  21322.  
  21323. This message comes from the shell and is the signal which terminated
  21324. your python process.
  21325.  
  21326. The signal "Killed" (signal 9) is sent by the kernel if it notices
  21327. that some resource (usually virtual memory) is unavailable.  It is
  21328. sent more or less at random to a process.  Apart from making sure that
  21329. your system doesn't get overloaded, there is nothing you can do about
  21330. this.  This particular signal cannot be caught or ignored.
  21331.  
  21332. Sjoerd Mullender
  21333. CWI, dept. CST, Kruislaan 413, 1098 SJ Amsterdam, Netherlands
  21334. email: Sjoerd.Mullender@cwi.nl        fax:   +31 20 592 4199
  21335. phone: +31 20 592 4127            telex: 12571 mactr nl
  21336. 
  21337. 
  21338. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  21339.     id AA01038 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 19:12:57 +0100
  21340. To: python-list@cwi.nl
  21341. Subject: INDEX from ftp.markv.com:/pub/python
  21342. X-Organization: Mark V Systems Ltd.
  21343. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  21344. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  21345. Date: Thu, 14 Oct 93 11:11:55 PDT
  21346. From: lance@markv.com
  21347. Sender: lance@markv.com
  21348. Message-Id:  <9310141111.aa06007@hermix.markv.com>
  21349. Source-Info:  From (or Sender) name not authenticated.
  21350.  
  21351.  
  21352. Welcome to one of Python's FTP sites!
  21353.  
  21354. In this directory you will find the latest version of Python
  21355. as well as some documentation on it. You will also find some useful
  21356. scripts and modules that are not part of the distribution.
  21357.  
  21358. There is also a Python mailing list.
  21359.  
  21360. To join, send a message to:
  21361.     python-list-request@cwi.nl
  21362.  
  21363. The Python distribution is mirrored from:
  21364.     ftp.cwi.nl:/pub/python
  21365.  
  21366. If you have any questions/comments/problems with any of the files
  21367. listed, please contact the author directly.
  21368.  
  21369. If you would like to post anything to this FTP site, please
  21370. create a <whatever file>.readme file and then FTP all necessary
  21371. files to ftp.markv.com:/incoming/python
  21372. This directory is a "drop directory". You will not be able to see anything
  21373. in that directory.. Then please drop me an Email and let me know it is
  21374. there.. I will add it to this INDEX file and let everyone know.
  21375.  
  21376. Thank you and enjoy!
  21377. Lance Ellinghouse
  21378. lance@markv.com
  21379.  
  21380.  
  21381. Index of ftp.markv.com:/pub/python
  21382.  
  21383. Files:
  21384.     python0.9.9.tar.gz
  21385. Author:
  21386.     Guido.van.Rossum@cwi.nl
  21387. Description:
  21388.     Python distribution version 0.9.9
  21389.  
  21390. Files:
  21391.     pythondoc-ps0.9.9.tar.gz
  21392. Author:
  21393.     Guido.van.Rossum@cwi.nl
  21394. Description:
  21395.     PostScript documentation for Python distribution version 0.9.9
  21396.  
  21397.  
  21398. Files:
  21399.     Dates.py
  21400.     Dates.readme
  21401. Author:
  21402.     Tim Peters <tim@ksr.com>
  21403. Description:
  21404.     Date manipulation class
  21405.     See Dates.readme and Dates.py for more info..
  21406.  
  21407.  
  21408. 
  21409. 
  21410. Replied: Thu, 14 Oct 1993 19:26:52 +0100
  21411. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> "
  21412. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  21413.     id AA01133 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 19:22:48 +0100
  21414. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa02157;
  21415.           14 Oct 93 14:22 EDT
  21416. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  21417.     id AA14545; Thu, 14 Oct 1993 14:22:23 -0400
  21418. Date: Thu, 14 Oct 1993 14:22:23 -0400
  21419. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  21420. Message-Id: <199310141822.AA14545@elvis.med.Virginia.EDU>
  21421. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  21422. To: python-list@cwi.nl
  21423. Subject: Re: Killed
  21424.  
  21425.  
  21426. Thanks everyone!
  21427. I thought it *looked* more like a unix shell message - that terse single 
  21428. word with no other explaination: 'Killed' ! 
  21429.  
  21430. None of the machine limits looked likely, and since it seemed to
  21431. happen in the same point in the file, I managed to 'manually' 
  21432. restart it near that point, and after a pause in the output
  21433. stream occurred, I hit ^C - where upon I got several pages of
  21434. stack trace from python indicating that I have a *slight*
  21435. recursion-gone-wild bug in my python code. 
  21436.  
  21437. Another tribute to the benefits of interactive programming: 
  21438. not only had I THOUGHT that my code had been pretty well 
  21439. tested, but it successfully ran on about 200,000 blocks 
  21440. of a 300,000 block file, before it ran into the "right" 
  21441. test case. 
  21442.  
  21443. It WOULD have been nicer if Python could have intercepted 
  21444. the problem and given me a nicer message, without having 
  21445. had to force the stack dump with ^C ( i.e. at that point,
  21446. I had already sort of guessed what the problem must be, 
  21447. and was looking for the where. ) but from the replies I
  21448. got, it looks like there is nothing Python can do about 
  21449. catching the Kill signal. [ fodder for one of the comp.unix
  21450. news groups: should unix first try signaling with a 
  21451. "catchable" signal before trying the final irrevokable kill ? 
  21452. i.e. "STOP WHATEVER YOU"RE DOING", ... "NO - I *REALLY* MEAN IT!" 
  21453. I mean, that *IS* the typical mode of parent/child interaction!
  21454. Isn't it? ;-) ]
  21455.  
  21456.  
  21457. - Steve M.
  21458. 
  21459. 
  21460. Received: from boulder.Colorado.EDU by charon.cwi.nl with SMTP
  21461.     id AA01454 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 19:49:11 +0100
  21462. Received: from vette.Colorado.EDU by boulder.Colorado.EDU with SMTP id AA22998
  21463.   (5.65c/IDA-1.4.4 for <@boulder.colorado.edu:python-list@cwi.nl>); Thu, 14 Oct 1993 12:49:05 -0600
  21464. Received: by vette.colorado.edu (920330.SGI/911001.SGI)
  21465.     for @boulder.colorado.edu:python-list@cwi.nl id AA21685; Thu, 14 Oct 93 12:49:04 -0600
  21466. Date: Thu, 14 Oct 93 12:49:04 -0600
  21467. From: michel@vette.colorado.edu (Michel Lesoinne)
  21468. Message-Id: <9310141849.AA21685@vette.colorado.edu>
  21469. To: python-list@cwi.nl
  21470. Subject: Termcap /curses
  21471.  
  21472. Is it possible to use termcap and or curses on python ?
  21473. Has anybody done it, or should I make my own extension to python ?
  21474.  
  21475. Michel
  21476.  
  21477. 
  21478. 
  21479. Replied: Fri, 15 Oct 1993 10:16:30 +0100
  21480. Replied: "python-list "
  21481. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  21482.     id AA01691 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 20:10:24 +0100
  21483. To: michel@vette.colorado.edu
  21484. Cc: python-list@cwi.nl
  21485. In-Reply-To: <9310141849.AA21685@vette.colorado.edu> (message from Michel Lesoinne on Thu, 14 Oct 93 12:49:04 -0600)
  21486. Subject: Re: Termcap /curses
  21487. X-Organization: Mark V Systems Ltd.
  21488. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  21489. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  21490. Date: Thu, 14 Oct 93 12:09:09 PDT
  21491. From: lance@markv.com
  21492. Sender: lance@markv.com
  21493. Message-Id:  <9310141209.aa13155@hermix.markv.com>
  21494. Source-Info:  From (or Sender) name not authenticated.
  21495.  
  21496.  > Is it possible to use termcap and or curses on python ?
  21497.  
  21498.  Currently there is no termcap or curses module for python
  21499.  
  21500.  > Has anybody done it, or should I make my own extension to python ?
  21501.  
  21502.  I need one also.. I was thinking of making it myself.. just have
  21503. not had the time. I would be happy to help if I can..
  21504.  
  21505. --
  21506.  
  21507. Lance Ellinghouse           lance@markv.com
  21508.  
  21509. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  21510. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  21511. You can receive my Public Key by `finger lance@markv.com`
  21512. 
  21513. 
  21514. Received: from boring.cwi.nl by charon.cwi.nl with SMTP
  21515.     id AA02451 (5.65b/3.11/CWI-Amsterdam); Thu, 14 Oct 1993 21:26:48 +0100
  21516. Received: by boring.cwi.nl 
  21517.     id AA10840 (4.1/2.10/CWI-Amsterdam); Thu, 14 Oct 93 21:26:48 +0100
  21518. Date: Thu, 14 Oct 93 21:26:48 +0100
  21519. From: Dik.Winter@cwi.nl
  21520. Message-Id: <9310142026.AA10840.dik@boring.cwi.nl>
  21521. To: python-list@cwi.nl
  21522. Subject: Re: Killed
  21523.  
  21524. The base problem is with AIX which does lazy allocation of resources
  21525. (memory in special).  I.e. "malloc" always succeeds!  There appears to
  21526. be in later versions of AIX a version of "malloc" which actually tells
  21527. whether it did succeed or not.
  21528.  
  21529. dik
  21530. 
  21531. 
  21532. Forwarded: Wed, 03 Nov 1993 16:08:30 +0100
  21533. Forwarded: "jredford@lehman.com "
  21534. Replied: Fri, 15 Oct 1993 11:45:32 +0100
  21535. Replied: "Bill Janssen <janssen@parc.xerox.com> "
  21536. Replied: Fri, 15 Oct 1993 10:51:35 +0100
  21537. Replied: "Bill Janssen <janssen@parc.xerox.com> "
  21538. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  21539.     id AA04995 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 01:02:33 +0100
  21540. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11786>; Thu, 14 Oct 1993 17:02:02 PDT
  21541. Received: by holmes.parc.xerox.com id <16134>; Thu, 14 Oct 1993 17:01:59 -0700
  21542. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  21543.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  21544.           Thu, 14 Oct 1993 17:01:45 -0700 (PDT)
  21545. Message-Id: <sgjSVd4B0KGWNDk0Zx@holmes.parc.xerox.com>
  21546. Date:     Thu, 14 Oct 1993 17:01:45 PDT
  21547. Sender: Bill Janssen <janssen@parc.xerox.com>
  21548. From: Bill Janssen <janssen@parc.xerox.com>
  21549. To: python-list@cwi.nl
  21550. Subject: Python & Sun shared libraries
  21551.  
  21552. Denis Severson and I tried modifying Python to use the SunOS dynamic
  21553. linking, and shared libraries.  Seems to work just fine.  Here are the
  21554. diffs (from the 0.9.9 sources) for import.c (the only file which needed
  21555. to change):
  21556.  
  21557. *** import.c-dist    Wed Oct 13 16:45:54 1993
  21558. --- import.c    Wed Oct 13 17:40:27 1993
  21559. ***************
  21560. *** 47,53 ****
  21561. --- 47,58 ----
  21562.   #endif
  21563.   
  21564.   #ifdef USE_DL
  21565. + #ifdef SUN_SHLIB
  21566. + #include <dlfcn.h>
  21567. + typedef void (*dl_funcptr)();
  21568. + #else
  21569.   #include "dl.h"
  21570. + #endif /* SUN_SHLIB */
  21571.   
  21572.   extern char *argv0;
  21573.   #endif
  21574. ***************
  21575. *** 98,104 ****
  21576. --- 103,113 ----
  21577.   
  21578.   #define PY_SUFFIX    ".py"
  21579.   #ifdef USE_DL
  21580. + #ifdef SUN_SHLIB
  21581. + #define O_SUFFIX    "module.so"
  21582. + #else
  21583.   #define O_SUFFIX    "module.o"
  21584. + #endif /* SUN_SHLIB */
  21585.   #endif
  21586.   
  21587.   /* Find and open a module file, using sys.path.
  21588. ***************
  21589. *** 183,189 ****
  21590. --- 192,205 ----
  21591.               dl_funcptr p;
  21592.               D(fprintf(stderr, "Found %s\n", namebuf));
  21593.               sprintf(funcname, "init%s", name);
  21594. + #ifdef SUN_SHLIB
  21595. +             {
  21596. +               void *handle = dlopen (namebuf, 1);
  21597. +               p = (dl_funcptr) dlsym(handle, funcname);
  21598. +             }
  21599. + #else
  21600.               p =  dl_loadmod(argv0, namebuf, funcname);
  21601. + #endif /* SUN_SHLIB */
  21602.               if (p == NULL) {
  21603.                   D(fprintf(stderr, "dl_loadmod failed\n"));
  21604.               }
  21605.  
  21606. To link python dynamically under SunOS, just remove the -Bstatic flag
  21607. when linking, and define the SUN_SHLIB flag when compiling import.c.
  21608.  
  21609. To create a new object module that is capable of being dynamically
  21610. loaded, type "ld -o foomodule.so foomodule.c".  Note the ".so" suffix.
  21611.  
  21612. I'd really like to be able to move stdwin to a dynamically loaded object
  21613. module, but there is stdwin-specific code in config.c which makes some
  21614. initialization and finalization calls to the STDWIN library.  Could that
  21615. code be moved/replaced?
  21616.  
  21617. Bill
  21618. 
  21619. 
  21620. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  21621.     id AA12526 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 10:16:31 +0100
  21622. Received: by voorn.cwi.nl with SMTP
  21623.     id AA09011 (5.65b/3.8/CWI-Amsterdam); Fri, 15 Oct 1993 10:16:31 +0100
  21624. Message-Id: <9310150916.AA09011=guido@voorn.cwi.nl>
  21625. To: python-list@cwi.nl
  21626. Subject: Re: Termcap /curses 
  21627. In-Reply-To: Your message of "Thu, 14 Oct 1993 12:09:09 MDT."
  21628.              <9310141209.aa13155@hermix.markv.com> 
  21629. From: Guido.van.Rossum@cwi.nl
  21630. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  21631. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  21632. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  21633. Date: Fri, 15 Oct 1993 10:16:30 +0100
  21634. Sender: Guido.van.Rossum@cwi.nl
  21635.  
  21636. >  > Is it possible to use termcap and or curses on python ?
  21637. >  Currently there is no termcap or curses module for python
  21638. >  > Has anybody done it, or should I make my own extension to python ?
  21639. >  I need one also.. I was thinking of making it myself.. just have
  21640. > not had the time. I would be happy to help if I can..
  21641.  
  21642. Note that in principle you could do it all in Python -- with the
  21643. (optional) fcntl module you can make the necessary ioctl calls and
  21644. then just read the termcap file and generate the proper calls.
  21645.  
  21646. Alternatively, there's a "character-cell device" version of STDWIN
  21647. (the "alfa" port) which uses termcap.  It is line oriented but has the
  21648. advantage of making the transition from a termcap application to a
  21649. windowing application relly smooth...
  21650.  
  21651. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  21652. 
  21653. 
  21654. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  21655.     id AA21331 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 17:56:55 +0100
  21656. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  21657.     id AA04999; Fri, 15 Oct 93 09:57:30 -0700
  21658. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  21659.     id AA27066; Fri, 15 Oct 93 09:57:05 -0700
  21660. Received: by ushqgw.sequent.com with Microsoft Mail
  21661.     id <2CBED431@ushqgw.sequent.com>; Fri, 15 Oct 93 09:47:45 PDT
  21662. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  21663. To: guido <guido@cwi.nl>, python-list <python-list@cwi.nl>
  21664. Subject: Re: Termcap /curses
  21665. Date: Fri, 15 Oct 93 09:47:00 PDT
  21666. Message-Id: <2CBED431@ushqgw.sequent.com>
  21667. Encoding: 12 TEXT
  21668. X-Mailer: Microsoft Mail V3.0
  21669.  
  21670.  
  21671.  
  21672. | Note that in principle you could do it all in Python -- with the
  21673. | (optional) fcntl module you can make the necessary ioctl calls and
  21674. | then just read the termcap file and generate the proper calls.
  21675.  
  21676. You would have to re-implement the mapping from generic terminfo/termcap 
  21677. strings to actual escape sequences including padding; reimplement some form 
  21678. of curses etc. etc. Not that it couldn't be done, but I think you're getting 
  21679. into more than you ever bargained for...
  21680.  
  21681.      -Jaap-
  21682. 
  21683. 
  21684. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  21685.     id AA21758 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 18:24:24 +0100
  21686. To: jaap@sequent.com
  21687. Cc: guido@cwi.nl, python-list@cwi.nl
  21688. In-Reply-To: <2CBED431@ushqgw.sequent.com> (jaap@sequent.com)
  21689. Subject: Re: Termcap /curses
  21690. X-Organization: Mark V Systems Ltd.
  21691. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  21692. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  21693. Date: Fri, 15 Oct 93 10:23:02 PDT
  21694. From: lance@markv.com
  21695. Sender: lance@markv.com
  21696. Message-Id:  <9310151023.aa18159@hermix.markv.com>
  21697. Source-Info:  From (or Sender) name not authenticated.
  21698.  
  21699.  > | Note that in principle you could do it all in Python -- with the
  21700.  > | (optional) fcntl module you can make the necessary ioctl calls and
  21701.  > | then just read the termcap file and generate the proper calls.
  21702.  > 
  21703.  > You would have to re-implement the mapping from generic terminfo/termcap 
  21704.  > strings to actual escape sequences including padding; reimplement some form 
  21705.  > of curses etc. Not that it couldn't be done, but I think you're getting 
  21706.  > into more than you ever bargained for...
  21707.  
  21708.  Not only this, but the curses packages also take into account terminals
  21709. that have strange behavior.. I can see a LOT of recoding trying to 
  21710. make a PYTHON version of curses instead of just creating an interface to
  21711. it.. Also, by recreating a python version, I would not have
  21712. any of the menu and form libraries available that come with my
  21713. curses libraries..
  21714.  
  21715. --
  21716.  
  21717. Lance Ellinghouse           lance@markv.com
  21718.  
  21719. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  21720. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  21721. You can receive my Public Key by `finger lance@markv.com`
  21722. 
  21723. 
  21724. Received: from uunet.ca by charon.cwi.nl with SMTP
  21725.     id AA22215 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 19:05:58 +0100
  21726. Received: from tsltor by mail.uunet.ca with UUCP id <102122(5)>; Fri, 15 Oct 1993 14:05:44 -0400
  21727. Received: from osprey.teleride.on.ca by falcon.teleride.on.ca with smtp
  21728.     (Smail3.1.26.7 #5) id m0ontVz-0000eOC; Fri, 15 Oct 93 14:04 EDT
  21729. Received: by vax.teleride.on.ca (MX V3.0A) id 31251; Fri, 15 Oct 1993 14:02:34
  21730.           EDT
  21731. Sender: <lou@VAX.TELERIDE.ON.CA>
  21732. Date:     Fri, 15 Oct 1993 14:02:41 -0400
  21733. From: Lou Kates <lou@VAX.TELERIDE.ON.CA>
  21734. To: python-list@cwi.nl
  21735. Message-Id: <009740EC.69AFD6A0.31251@vax.teleride.on.ca>
  21736. Subject: Re: Termcap /curses
  21737.  
  21738. > > | Note that in principle you could do it all in Python -- with the
  21739. > > | (optional) fcntl module you can make the necessary ioctl calls and
  21740. > > | then just read the termcap file and generate the proper calls.
  21741. > >
  21742. > > You would have to re-implement the mapping from generic terminfo/termcap
  21743. > > strings to actual escape sequences including padding; reimplement some form
  21744. > > of curses etc. Not that it couldn't be done, but I think you're getting
  21745. > > into more than you ever bargained for...
  21746. >
  21747. > Not only this, but the curses packages also take into account terminals
  21748. >that have strange behavior.. I can see a LOT of recoding trying to
  21749. >make a PYTHON version of curses instead of just creating an interface to
  21750. >it.. Also, by recreating a python version, I would not have
  21751. >any of the menu and form libraries available that come with my
  21752. >curses libraries..
  21753. >
  21754.  
  21755. Another approach would be  to  develop  a C to Python translator.
  21756. That would also be a large amount of  work  and  its  conceivable 
  21757. that certain features would have to be added to Python to make it 
  21758. feasible but it would allow one to translate not only the bulk of 
  21759. the curses source but many other C libraries all in one go.
  21760.  
  21761. Lou Kates, louk@teleride.on.ca
  21762. 
  21763. 
  21764. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  21765.     id AA22512 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 19:37:50 +0100
  21766. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  21767.     id AA09442; Fri, 15 Oct 93 11:38:26 -0700
  21768. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  21769.     id AA00535; Fri, 15 Oct 93 11:46:35 -0700
  21770. Received: by ushqgw.sequent.com with Microsoft Mail
  21771.     id <2CBEEDDB@ushqgw.sequent.com>; Fri, 15 Oct 93 11:37:15 PDT
  21772. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  21773. To: python-list <python-list@cwi.nl>,
  21774.         lou <tsltor!vax.teleride.on.ca!lou@mail.uunet.ca>
  21775. Subject: Re: Termcap /curses
  21776. Date: Fri, 15 Oct 93 11:33:00 PDT
  21777. Message-Id: <2CBEEDDB@ushqgw.sequent.com>
  21778. Encoding: 14 TEXT
  21779. X-Mailer: Microsoft Mail V3.0
  21780.  
  21781.  
  21782.  
  21783. | Another approach would be  to  develop  a C to Python translator.
  21784. | That would also be a large amount of  work  and  its  conceivable
  21785. | that certain features would have to be added to Python to make it
  21786. | feasible but it would allow one to translate not only the bulk of
  21787. | the curses source but many other C libraries all in one go.
  21788.  
  21789. I'm afraid that you would lose the object oriented aspect of Python, which 
  21790. is the most valuable aspect of Python modules that interact with certain 
  21791. facets of POSIX. As an example look at the socket module. If the translation 
  21792. does not allow this kind of abstraction, it would be useless IMHO.
  21793.  
  21794.      -Jaap-
  21795. 
  21796. 
  21797. Replied: Mon, 18 Oct 1993 21:26:49 +0100
  21798. Replied: "tb06@PL122e.EECS.Lehigh.EDU (TERRENCE BRANNON) "
  21799. Received: from pl122e.eecs.lehigh.edu by charon.cwi.nl with SMTP
  21800.     id AA22897 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 20:14:22 +0100
  21801. Received: by PL122e.EECS.Lehigh.EDU (5.61/1.34)
  21802.     id AA00535; Fri, 15 Oct 93 15:01:32 -0400
  21803. Date: Fri, 15 Oct 93 15:01:32 -0400
  21804. From: tb06@PL122e.EECS.Lehigh.EDU (TERRENCE BRANNON)
  21805. Message-Id: <9310151901.AA00535@PL122e.EECS.Lehigh.EDU>
  21806. To: python-list@cwi.nl
  21807. Subject: [request] Impressive Python Software
  21808.  
  21809.  
  21810. I am getting ready to post another copy of my paper:
  21811. "Survey of Quick Interpreted Languages" to Usenet. However, before I do so, I
  21812. would like to know what impressive software has been developed with Python. I
  21813. am including a Beta copy of my paper. Note the chapter "Significant software"
  21814.  
  21815. Terrence Brannon ...... tb06@pl122e.eecs.lehigh.edu
  21816. Address ............... PO Box 5027, Bethelehem, PA 18015
  21817. Phone ................. 215-758-4081. 215-758-0780
  21818.  
  21819. \documentstyle{report}
  21820. \pagestyle{headings}
  21821. \begin{document}
  21822.  
  21823. \title {
  21824.    Survey of Quick Interpreted Languages
  21825. }
  21826.  
  21827. \author {
  21828.    Terrence Monroe Brannon \\ 
  21829.    PO Box 5027 \\ 
  21830.    Bethlehem, PA 18015 \\
  21831.    $tb06@pl122e.eecs.lehigh.edu$
  21832. }     
  21833.  
  21834. \maketitle
  21835.  
  21836. \tableofcontents
  21837.  
  21838.  
  21839. %%% 1. \part {Introduction} %%%
  21840.  
  21841. \part {Introduction}
  21842.  
  21843. The purpose of this FAQ is to expose people to several languages which
  21844. can cutdown/eliminate shell programming and C programming.
  21845.  
  21846. All of these languages are quick interpreted languages which can do
  21847. things in a few lines which might take hundreds of lines of C/shell
  21848. code. 
  21849.  
  21850. These languages are evaluated in terms of the three things that any
  21851. programmer desires from a language: power, speed, and ease of use. Power
  21852. means a wealth of libraries for any task needed. Speed needs no
  21853. explanation. Ease of use includes how well documented the language is, how
  21854. much support there is for problems with the language, and how cleanly
  21855. extensible the language is.
  21856.  
  21857. \section {The Languages}
  21858. \begin{description}
  21859.  
  21860. \item[Scheme: Elk version]
  21861. Elk is a Scheme interpreter intended to be used as a general, reusable
  21862. extension language subsystem for integration into existing and future
  21863. applications.  Elk can also be used as a stand-alone implementation of
  21864. the Scheme programming language.
  21865.  
  21866. One purpose of the Elk project is to end the recent proliferation of
  21867. mutually incompatible Lisp-like extension languages.  Instead of
  21868. inventing and implementing yet another extension language, application
  21869. programmers can integrate Elk into their application to make it
  21870. extensible and highly customizable.
  21871.  
  21872. The Elk project was started in 1987 to support ISOTEXT, an ODA-based
  21873. document system (a WYSIWYG editor) that is being developed at the
  21874. Technical University of Berlin.  Elk has been successfully demonstrated
  21875. as the extension language kernel of ISOTEXT, e.g. at the Hanover Fair 1989.
  21876.  
  21877. We feel that Scheme is better suited as a general extension language
  21878. than other Lisp dialects:  it is sufficiently small to not dwarf the
  21879. application it serves and to be fully understood with acceptable
  21880. effort; it is orthogonal and well-defined.  In addition, Scheme has
  21881. been recognized to be mature enough for national and international
  21882. standardization (IEEE P1178, ISO/IEC JTC1/SC22/WG16).
  21883.  
  21884. The Elk Scheme implementation is R4RS and P1178 conforming (with the
  21885. exception of the number system and a few other details that are listed
  21886. in the documentation).
  21887.  
  21888. Elk supports several additional language features to increase its
  21889. usability as an extension language, among them dynamic, incremental
  21890. loading of object files and `freezing' of a fully customized
  21891. application into a new executable file (`dump').
  21892.  
  21893. Other additional features of the Scheme implementation are:
  21894.  
  21895. \begin{itemize}
  21896. \item  a simple macro facility
  21897. \item  environments as first-class objects
  21898.       \item  dynamic-wind, fluid-let
  21899.       \item  autoloading, provide/require
  21900. \end{itemize}
  21901.  
  21902. The current release of Elk includes several dynamically-loadable
  21903. extensions, among them interfaces to the X11 Xlib and to the application
  21904. programmer interface of the Xt intrinsics, and interfaces to the Athena
  21905. and OSF/Motif widget sets.
  21906.  
  21907. As an alternative to the stop-and-copy garbage collector provided with
  21908. earlier versions of Elk, the Scheme interpreter now supports a
  21909. generational, incremental garbage collector.  The generational garbage
  21910. collector is more efficient and thus reduces the time the application
  21911. is disrupted by a garbage collection.  On platforms supporting advanced
  21912. memory management, the garbage collector can be switched to
  21913. `incremental' mode, further reducing wait times.
  21914.  
  21915. \item {Lisp: Emacs version}
  21916. Anything Emacs does is done in Lisp, so you can do it to. This means you
  21917. can have automatic completion of input, full screen editing, buffering
  21918. routines and much more. But you can only do it inside of Emacs Lisp for
  21919. the most part. The two work arounds are: (1) use emacs-server.el which
  21920. allows Emacs to send/receive onsockets (2) use emacs server mode. (3) I
  21921. am currently working on extracting the interpreter from Emacs so that it
  21922. is callable from C.
  21923.  
  21924. Emacs' only interaction with other programs is through its batch mode
  21925. which is callable from C or shell scripts. C programs cannot use Emacs
  21926. routines and Emacs cannot call C. Emacs can call shell scripts and
  21927. supply command line arguments as well. 
  21928.  
  21929.  
  21930. \item[Perl]
  21931. Combines the best features of awk, sed, and shell programming. The
  21932. latest version can be embedded in C programs. It is also easy to call
  21933. from the shell. 
  21934.  
  21935. The embeddable version, which is perl5, is not yet out for public release
  21936. quite yet.  I would say that you should include C as "the best features"
  21937. of list, since one of its strong points is easy access to unix syscalls
  21938. and C library features.
  21939.  
  21940. Perl can be linked with external C libraries, such as curses or 
  21941. database accessing libraries, like oracle or sybase, making for 
  21942. easy access to screen-based form programs to deal with your dbase.
  21943.  
  21944. The Wafe server lets you get at X from perl.
  21945.  
  21946. \item[Python]
  21947. An object-oriented interpreted language. Callable from C as well as the
  21948. shell. Interpretation may be sidestepped through the use of the
  21949. byte-compiler on files. Python played a major role in testing Amoeba, a
  21950. distributed operating system developed at CWI.
  21951.  
  21952. \item[Tcl]
  21953. Extremely strong in X-windows. It can do a 5 page x-windows program in
  21954. *2* lines and more. Callable from C and from the shell.
  21955.  
  21956. \end{description}
  21957.  
  21958. \section{Obtaining}
  21959.  
  21960.  
  21961. All of these packages are publicly available via ftp.
  21962. I have chosen the ange-ftp method of representing ftp
  21963. connections for its conciseness. The following:
  21964. "/anonymous@src.doc.ic.ac.uk:/pub/gnu" means make an anonymous ftp
  21965. connection to src.doc.ic.ac.uk then cd to /pub/gnu.
  21966.  
  21967. As a side note, if you had Hyperbole (an Emacs-based hypertext package)
  21968. installed and running under X-Windows, you could just click on the
  21969. quotation-mark-enclosed pathname above and you would automatically be
  21970. connected to the above directory. 
  21971.  
  21972. All documentation and source code have their copyright status with the
  21973. distribution. Consult the distribution for information on using these
  21974. products as part of your own creative work.
  21975.  
  21976. \begin{description}
  21977. \item[Emacs Lisp]
  21978. "/anonymous@src.doc.ic.ac.uk:/pub/gnu"
  21979. "/anonymous@prep.ai.mit.edu:/pub/gnu"
  21980. \item[Perl]
  21981. "/anonymous@convex.com:/pub/perl"
  21982. "/anonymous@archive.cs.ruu.nl:/DOC"
  21983. \item[Python]
  21984. "/anonymous@ftp.cwi.nl:/pub"
  21985. \item[Tcl]
  21986. "/anonymous@ftp.uu.net:/languages/tcl"
  21987. "/anonymous@barkley.berkeley.edu:/tcl"
  21988. \end{description}
  21989.  
  21990. \section{The Future}
  21991.  
  21992. \begin{itemize}
  21993.  
  21994. \item
  21995. Emacs Lisp does not have object-oriented extensions yet Python does.
  21996.  
  21997. Python does not yet have a robust ftp interface like Emacs' ange-ftp nor
  21998. does it have an advanced desk top calculator like Emacs's calc. However
  21999. it does have STDWIN, an easy-to-use windowing system. 
  22000.  
  22001. Expression of mathematics in Tcl is cumbersome yet X11 graphics is very
  22002. very easy. 
  22003.  
  22004. Perl has excellent string and manipulation tools and a ton of sysadmin
  22005. utilities written in it.
  22006.  
  22007. The bottom line is that all of these languages have powerful tools ready
  22008. to use. Each language also has its weak points. Instead of being stuck
  22009. in each language and slaving through its weakness (or lack of a certain
  22010. utility), one should be able to fire up an interpreter in any of these
  22011. other languages and let it perform on it strong points and return the
  22012. answer.
  22013.  
  22014. I expect this type of hybrid programming to become almost necessary with
  22015. excellent packages and large being written for each langauge. 
  22016.  
  22017. \item
  22018. I am currently working on socketed interprocess communication between a
  22019. Python interpreter and Emacs Lisp. Next will be Tcl. Perhaps next will
  22020. be postscript or maybe Perl. 
  22021.  
  22022. \item
  22023. A trans-language browser. If you see that a Perl script has been
  22024. written to traverse a directory tree and count the number of files
  22025. ending in .o whose age is more than 20 days but you are not a Perl
  22026. programmer, that Perl script should become and OBJECT to which you SEND
  22027. a message to get that work done.
  22028.  
  22029.  
  22030. \end{itemize}
  22031.  
  22032.  
  22033. %%% 2. \part {Power} %%%
  22034.  
  22035. \part {Power}
  22036.  
  22037. %%% 2.1. \chapter {Significant Software} %%%
  22038.  
  22039. \chapter {Significant Software}
  22040. An important feature of these languages is how much is already there for
  22041. you to use.
  22042.  
  22043. %%% 2.1.1. \section {Emacs Lisp} %%%
  22044.  
  22045. \section {Emacs Lisp}
  22046.  
  22047. \begin{description}
  22048. \item[Folding Mode] Allows for hierarchical editing of structured text
  22049. files. I use it all the time. You can move through and edit any document
  22050. (program, LaTeX file, whatever) much faster using folding mode.
  22051. \item[VM] A mail reader that does everything that I need. 
  22052. \item[Gnus] A Usenet reader that can save articles to mail folders for
  22053. later recall. I often save articles in Gnus and later read them using VM.
  22054. \item[EDB]  full featured database
  22055. \item[Ange-FTP] An excellent ftp utility which allows transparent
  22056. file access/modification with the ease of a few keystrokes.
  22057. \item[user interfaces] Countless interfaces for everything from Archie to
  22058. MUD role playing games.
  22059. \item[AUC-TeX] Allows you to do anything you would want to do with
  22060. TeX/LaTeX from an Emacs buffer quickly and easily.
  22061. \item[Calc] The poor man's Mathematica. Includes rewrite rules and
  22062. functionality on the order of the HP-28.
  22063. \item[VIP] vi emulation for emacs
  22064. \item[Calendar/Diary] Calendar and appointment manager within Emacs
  22065. \item[Tree Dired] Allows you to scroll through directories and copy, edit,
  22066. remove, view files. And more
  22067. \item[Hyperbole] Extensible hypertext management system within Emacs. 
  22068. \end{description}
  22069.  
  22070. %%% 2.1.2. \section {Perl} %%%
  22071.  
  22072. \section {Perl}
  22073. Having been publicly available for six years now, Perl has a truly huge
  22074. body of code already written for it.  I couldn't begin to document all of
  22075. them.  More than any other language listed herein, it is the tool of
  22076. choice for Unix system administrators.  Perl comes with a symbolic
  22077. debugger, a bunch of libraries, various tools, and and numerous example
  22078. programs, but that's just the start.  
  22079.  
  22080. %%% 2.1.3. \section {Python} %%%
  22081.  
  22082. \section {Python}
  22083. \begin{enumerate}
  22084. \item 
  22085. ?? -- Multimedia interface. 
  22086. \item 
  22087. ?? -- Remote Procedure Call debugger
  22088. \item 
  22089. texfix -- Crude convert latex to texinfo
  22090. \item 
  22091. throughput -- measure tcp throughput
  22092. \item 
  22093. dutree -- format du(1) output at a tree sorted by size
  22094. \item 
  22095. findlinks -- recursively find links to a given path prefix
  22096. \item 
  22097. lpwatch -- watch BSD line printer queues
  22098. \item 
  22099. suff -- sort a list of files by suffix 
  22100. \end{enumerate}
  22101.  
  22102. %%% 2.1.4. \section {Tcl} %%%
  22103.  
  22104. \section {Tcl}
  22105. \begin{enumerate}
  22106. \item[Tcl-DP] Layered distributed computing for Tcl. Tcl-DP adds TCP and IP
  22107. connection management, remote procedure call (RPC), and distributed object
  22108. support to Tcl  
  22109. \item[Extended TCL] Adds keyed lists, a debugger and profiler and the full
  22110. suite of Unix process control primitives to Tcl.
  22111. \item[Objectify] Turns C++ classes into Tcl objects.
  22112. \item[Artcls] A graphic Usenet newsreader.
  22113. \item[TkWWW] A Tk world-wide web browser.
  22114. \item[XF] An X11 user interface builder
  22115. \item[WAFE] {\it W}idget {\it A}thena {\it F}ront {\it E}nd. Implemented in
  22116. Tcl, this package allows for the same generic graphic commands to be used
  22117. to develop user interfaces regardless of what language you are programming
  22118. in. All you need to do is interface to WAFE from your language. 
  22119. \item[PhotoWidget] A photo widget for Tk.
  22120. \item[TSipp] A Tcl interface to the SIPP 3-D rendering library.
  22121. \item[TkSteal] Allows for a Tk program to have an Emacs widget or a
  22122. Ghostscript widget.
  22123. \item[Pixmap] A color pixmap editor written in Tcl/Tk
  22124. \item[VOGLE] Awesome full-color 3-D rendering package with a ton of
  22125. fonts, both american and foreign.
  22126. \end{enumerate}
  22127.  
  22128. %%% 2.2. \chapter {Graphics} %%%
  22129.  
  22130. \chapter {Graphics}
  22131.  
  22132. \section{Emacs Lisp} 
  22133. None internally, but the ability to spawn inferior unix
  22134. processes and issue shell commands allows it to use tcl's WAFE or fire
  22135. up a Python process and control it with ease.
  22136.  
  22137. \section{Perl}
  22138. Again none interally, but the author of WAFE, the tcl/tk graphic
  22139. interpreter wrote all of his example programs in Perl (wafemail,
  22140. wafenews, wafeftp).
  22141.  
  22142. Certainly perl can issue external commands (inferior processes in lisp
  22143. parlance).  There is also a version of guiperl I've seen Larry demo
  22144. for me, so there's at least proof-of-concept that you can link in 
  22145. the X libs.  Whether it will come out with perl5 I don't know.
  22146.  
  22147.  
  22148. \section{Python}
  22149. Through the use of the STDWIN paradigm, the same source code
  22150. can do graphics in the following systems:
  22151.  
  22152. \begin{enumerate}
  22153. \item
  22154. X-windows
  22155. \item
  22156. Macintosh using either Think C 4.02 or MPW C 2.02
  22157. \item
  22158. Atari ST
  22159. \item
  22160. DOS
  22161. \item
  22162. Silicon Graphics SGI workstations
  22163. \end{enumerate}
  22164.  
  22165. This approach allows flexibility but means that no one graphics system's
  22166. potential is maximized. 
  22167.  
  22168. \section{Tcl}
  22169. Overloaded with all types of very very easy to do attractive
  22170. graphics in X-Windows only. Easy to learn, and has many nice widgets
  22171. added to it such as a photo widget for display of scanned PBM images,
  22172. a bar graph widget, an editable text widget and much more. 
  22173. Powerful tcl-based graphics systems come to mind:
  22174.  
  22175. \begin{enumerate}
  22176. \item
  22177. xy-graph - includes a Hypertext widget. This means that regardless of
  22178. what stream of information comes at your Tcl program, you can create
  22179. windows and paths through the stream on the fly. A major example of the
  22180. hypertext widget is Joseph Wang's World Wide Web Hypertext browser.
  22181. \item 
  22182. VOGLE - 3D rendering, fonts
  22183. \item 
  22184. BYO Interface Builder. A snap to use.
  22185. \item
  22186. XF - Another interface builder by the developers of TkEmacs. Arguably
  22187. as good as BYO.
  22188. \item 
  22189. WAFE . Send text string from anywhere (C language, Emacs, shell) to
  22190. a server and have the graphics done for you.
  22191. \item 
  22192. BOS - An object oriented extension for Tcl which also has some
  22193. widgets added to it.
  22194. \end{enumerate}
  22195.  
  22196. %%% 2.3. \chapter {User Interface Building} %%%
  22197.  
  22198. \chapter {User Interface Building}
  22199.  
  22200. \section{Emacs Lisp} 
  22201. None internally, but the ability to spawn inferior unix
  22202. processes and issue shell commands allows it to use tcl's WAFE or fire
  22203. up a Python process and control it with ease.
  22204.  
  22205. \section{Perl}
  22206. Again none interally, but the author of WAFE, the tcl/tk graphic
  22207. interpreter wrote all of his example programs in Perl (wafemail,
  22208. wafenews, wafeftp).
  22209.  
  22210. Certainly perl can issue external commands (inferior processes in lisp
  22211. parlance).  There is also a version of guiperl I've seen Larry demo
  22212. for me, so there's at least proof-of-concept that you can link in 
  22213. the X libs.  Whether it will come out with perl5 I don't know.
  22214.  
  22215.  
  22216. \section{Python}
  22217. Through the use of the STDWIN paradigm, the same source code
  22218. can do graphics in the following systems:
  22219.  
  22220. \begin{enumerate}
  22221. \item
  22222. X-windows
  22223. \item
  22224. Macintosh using either Think C 4.02 or MPW C 2.02
  22225. \item
  22226. Atari ST
  22227. \item
  22228. DOS
  22229. \item
  22230. Silicon Graphics SGI workstations
  22231. \end{enumerate}
  22232.  
  22233. This approach allows flexibility but means that no one graphics system's
  22234. potential is maximized. 
  22235.  
  22236. \section{Tcl}
  22237. Overloaded with all types of very very easy to do attractive
  22238. graphics in X-Windows only. Easy to learn, and has many nice widgets
  22239. added to it such as a photo widget for display of scanned PBM images,
  22240. a bar graph widget, an editable text widget and much more. 
  22241. Powerful tcl-based graphics systems come to mind:
  22242.  
  22243. \begin{enumerate}
  22244. \item
  22245. xy-graph - includes a Hypertext widget. This means that regardless of
  22246. what stream of information comes at your Tcl program, you can create
  22247. windows and paths through the stream on the fly. A major example of the
  22248. hypertext widget is Joseph Wang's World Wide Web Hypertext browser.
  22249. \item 
  22250. VOGLE - 3D rendering, fonts
  22251. \item 
  22252. BYO Interface Builder. A snap to use.
  22253. \item
  22254. XF - Another interface builder by the developers of TkEmacs. Arguably
  22255. as good as BYO.
  22256. \item 
  22257. WAFE . Send text string from anywhere (C language, Emacs, shell) to
  22258. a server and have the graphics done for you.
  22259. \item 
  22260. BOS - An object oriented extension for Tcl which also has some
  22261. widgets added to it.
  22262. \end{enumerate}
  22263.  
  22264. %%% 2.4. \chapter {String Handling} %%%
  22265.  
  22266. \chapter {String Handling}
  22267.  
  22268.  
  22269. \section{Emacs Lisp}
  22270. Strong. Many good string handling functions for operation on buffers as
  22271. well as string. Search replace backward and forward with regexps. Many
  22272. good string handling functions are found in tree-dired.el in gmhist*.el.
  22273. As well as in ange-ftp.el.
  22274.  
  22275. \section{Perl}
  22276. Very strong.
  22277.  
  22278. String-handling is one of Perl's strongest features: they are quite
  22279. powerful and extensive.  Strings can be as long as you want, and contain
  22280. binary data and nulls.  This works:
  22281. \begin{verbatim}
  22282.     $kernel = `cat /vmunix`;
  22283. \end{verbatim}
  22284.  
  22285. Perl has a wealth of string-accessing functions, including matching,
  22286. substitution, transliteration, splitting, and direct substring accessing.
  22287. Strings and numbers are interchangeable.  The regexps are a superset of
  22288. other regexp syntaxes, with extensions.  Parsing is very easy:
  22289. \begin{verbatim}
  22290.     ($name, $number, $host) = /(\w+)=(\d+)( from @(\w+))?/;
  22291. \end{verbatim}
  22292. Subexpressions can nest, and be arbitrarily deep: you don't have
  22293. to stop with \\9, but can keep going.
  22294.  
  22295. Perl's substitution operator works like sed's:
  22296. \begin{verbatim}
  22297.     s/foo/bar;
  22298. \end{verbatim}
  22299. or
  22300. \begin{verbatim}
  22301.     $a =~ s/foo/bar/g;
  22302. \end{verbatim}
  22303. but can do much more, like:
  22304. \begin{verbatim}
  22305.     s/(\d+)/sprintf("0x%08x", $1)/ge;
  22306. \end{verbatim}
  22307. to find all the numbers in the pattern space and replace them 
  22308. with the hex representation of the same.  It has other powerful
  22309. features I don't have time or space to go into.
  22310.  
  22311. Perl also lets you treat strings as raw bitwise data, so 
  22312. \begin{verbatim}
  22313.     substr($a,0,3) &= "\177\177\177";
  22314. \end{verbatim}
  22315. would clear the high bits on the first 3 bytes of \$a.  You
  22316. can also access strings bitwise, say, to check the $2456$th bit 
  22317. of a string.
  22318.  
  22319.  
  22320.  
  22321. \section{Python}
  22322. It has a string module and regexp module. It has all the string
  22323. @emph{search} capabilities of Emacs, but since strings are immutable in
  22324. Python, it understandably does not have Emacs Lisp's string replace power.
  22325.  
  22326. \section{Tcl}
  22327. Everything in Tcl is a string. It is very easy to map certain
  22328. string-intensive applications to Tcl. For example, I wrote a program to
  22329. do parallel library database searches in Tcl in about two weeks. Ranking
  22330. the 4 languages in terms of how easy it would have been: Tcl, Python,
  22331. Emacs, and I cant say about Perl because I gave up on Perl quickly after
  22332. buying the book and seeing all those registers and the confusing
  22333. context-intensive syntax. 
  22334.  
  22335. %%% 2.5. \chapter {Process Control} %%%
  22336.  
  22337. \chapter {Process Control}
  22338.  
  22339. \section {Emacs Lisp}
  22340. Has specialized modes for controlling Common and other lisps to
  22341. facilitate debugging, execution, and programming. Has shell modes with
  22342. command history. Has an excellent ftp program (ange-ftp). Can
  22343. asynchronously or synchronously call the shell and store the output in a
  22344. buffer or string. Can filter output from a process. However, the
  22345. filtering is somewhat hairy because you cannot be sure of the packet
  22346. size that the data will arrive in. In other words, it is easy to open a
  22347. pipe with Perl/Python/Tcl and just read lines at a time but you have to
  22348. write an accumulator function to do this in Emacs Lisp. However, the
  22349. interactor mode for GNU Smalltalk has an excellent accumulator function
  22350. that you could use in your own code. 
  22351.  
  22352. \section{Perl}
  22353. Perl has all the process control primitives available to you from C, plus
  22354. higher level constructs as well.  It's easy to open a pipe to or from
  22355. another process.  You can even open a pipe to an implicitly forked version
  22356. of yourself.   Standard Perl library routines allow bidirectional pipes
  22357. and running things over a pty via a package that works much like Don
  22358. Libes's Expect, save that it uses Perl instead of tcl as an extension
  22359. language.  Perl can also access all the socket and ipc functions on your
  22360. system without calling a program to do it.
  22361.  
  22362.  
  22363.  
  22364. \section{Python}
  22365. You would use pipes to do this in Python.
  22366.  
  22367. \section{Tcl}
  22368. Even stronger than Emacs. A package by Don Libes called Expect allows
  22369. the programmer to specify a set of expected regexps from the process and
  22370. what to do upon the receipt of the process output. Several of his papers
  22371. including "expect: Curing Those Uncontrollable Fits of Interaction"
  22372. available in postscript format for anonymous ftp from durer.cme.nist.giv
  22373. in pub/expect. 
  22374.  
  22375. There are also numerous process control extensions in Extended Tcl,
  22376. which will be detailed in the section titled extensions.
  22377.  
  22378. %%% 2.6. \chapter {Sample Programs} %%%
  22379.  
  22380. \chapter {Sample Programs}
  22381.  
  22382.  
  22383. To give you a taste of how each of these languages does its thing, I
  22384. have created some simple programs to give you an idea of how easy each
  22385. language can do some routine tasks.
  22386.  
  22387. None of the programs have been written for any of the languages for
  22388. this version of the FAQ. If you would like to contribute source, feel
  22389. free. Or if you have a program done in one of these languages that you
  22390. think would have been very difficult in one of the others let me know.
  22391.  
  22392. The programs are:
  22393.  
  22394. \begin{enumerate}
  22395.  
  22396. \item Write a program to count the number of files in the current directory.
  22397.  
  22398. \section{Emacs Lisp}
  22399. \begin{verbatim}
  22400. (defun current-directory-size ()
  22401.   ``Number of files in the current directory.''
  22402.   (length (directory-files ``.''))
  22403. \end{verbatim}
  22404.  
  22405. \section{Perl}
  22406. \begin{verbatim}
  22407.  
  22408.     #!/usr/bin/perl
  22409.     $count = @files = <*>;
  22410.     print "Directory file count: $count\n";
  22411.  
  22412.     #!/usr/bin/perl
  22413.     $count++ while <*>;
  22414.     print "Directory file count: $count\n";
  22415.  
  22416.     #!/usr/bin/perl
  22417.     print "Directory file count:", `ls | wc -l`;
  22418.  
  22419. # those didn't have dot files.  if you want dot files,
  22420. # use <* .*> instead.
  22421.  
  22422.     #!/usr/bin/perl
  22423.     opendir(DOT, '.');
  22424.     $count = @files = readdir(DOT);
  22425.     print "Directory file count: $count\n";
  22426.  
  22427.     #!/usr/bin/perl
  22428.     opendir(DOT, '.');
  22429.     $count++ while readdir(DOT);
  22430.     print "Directory file count: $count\n";
  22431.  
  22432. \end{verbatim}
  22433.  
  22434. \section{Tcl}
  22435. \begin{verbatim}
  22436.  
  22437. set count [ls | wc -l]
  22438.  
  22439. \end{verbatim}
  22440.  
  22441.  
  22442.  
  22443. \item
  22444. Write a program to run under X-Windows and Macintosh which opens a
  22445. window and prints {\tt "Hello, World"} in it. 
  22446.  
  22447. \section{Emacs Lisp}
  22448. \begin{verbatim}
  22449. (defun hello-world ()                   ; FSF Emacs 19 only.
  22450.   ``Open new frame with a friendly greeting.''
  22451.   (switch-to-buffer-other-frame ``*hello world*'')
  22452.   (insert ``Hello, World''))
  22453. \end{verbatim}
  22454.  
  22455. \section{Perl}
  22456. \begin{verbatim}
  22457. I'd just talk to Wafe or Stdwin.  Or call xterm. :-)
  22458. \end{verbatim}
  22459.  
  22460. \section{Tcl}
  22461.  
  22462. \begin{verbatim}
  22463.  
  22464. button .hello -text {Hello, World} -command {exit}
  22465. pack append . .hello {top}
  22466.  
  22467. \end{verbatim}
  22468.  
  22469. %---------------------------------------------------------------
  22470.  
  22471. \item
  22472. Given a file with 4 occurrences of the string "Hello Bob" find the file,
  22473. replace the last 3 occurrences of "Hello Bob" with "Hi James" and save
  22474. the file. The double quotation marks are for delineation purposes only.
  22475.  
  22476. \section{Emacs Lisp}
  22477. \begin{verbatim}
  22478. (defun Bob-meet-James (file)
  22479.   ``Replace all `Hello Bob' with `Hi James' in FILE except the first.''
  22480.   (save-excursion
  22481.     (find-file file)
  22482.     (goto-char (point-min))             ; We might already be editing it...
  22483.     (search-forward ``Hello Bob'')
  22484.     (while (search-forward ``Hello Bob'' nil t)
  22485.       (replace-match ``Hi James''))
  22486.     (save-buffer)))
  22487. \end{verbatim}
  22488.  
  22489.  
  22490. \section{Perl}
  22491. \begin{verbatim}
  22492. # the orig file will be in file.BAK -- if you don't want a backup,
  22493. # use just -i.
  22494.  
  22495. # remember that s//foo/ will match the last match
  22496.  
  22497. perl -i.BAK -p -e '/Hello Bob/ && $seen++ && s//Hi James/g'
  22498.  
  22499. or 
  22500.     perl thisprog < file.in > file.out
  22501.  
  22502.  
  22503.     #!/usr/bin/perl
  22504.     while (<>) {
  22505.     if (/Hello Bob/ && $seen++) {
  22506.         s//Hi James/g;
  22507.     } 
  22508.     print;
  22509.     } 
  22510. \end{verbatim}
  22511.  
  22512. \section{Tcl}
  22513.  
  22514. \begin{verbatim}
  22515.  
  22516.      set fdIn [open testFile r]
  22517.      set contents [read $fdIn]
  22518.      regexp -indices "Hello Bob" $contents matches
  22519.      regsub -all "Hello Bob" \
  22520.        [string range $contents [expr [lindex $matches 1]+1] end] \
  22521.        "Hi James" result
  22522.      close $fdIn
  22523.      set fdOut [open testFile w]
  22524.      puts $fdOut [string range $contents 0 [lindex $matches 1]]$result \
  22525.        nonewline
  22526.      close $fdOut
  22527.      exit
  22528.  
  22529. \end{verbatim}
  22530.  
  22531.  
  22532. \item
  22533. A lengthy file has been entered with records of the form:
  22534. \begin{verbatim}
  22535. <\n>NAME<\n>ADDRESS<\n>PHONE<\n>----------
  22536. \end{verbatim}
  22537. where \begin{verbatim}<\n>\end{verbatim} represents a line feed and the
  22538. \begin{verbatim}----------- \end{verbatim} is used to
  22539. separate records. Convert all entries in the file to a new format of
  22540. the form:
  22541. \begin{verbatim}<\n>NAME::ADDRESS::PHONE}
  22542. \end{verbatim}
  22543.  
  22544. \section{Emacs Lisp}
  22545. \begin{verbatim}
  22546. (defun newline-to-double-colon ()
  22547.   ``Convert current buffer from old style to new style address book
  22548. format.''
  22549.   (goto-char (point-min))
  22550.   (while (re-search-forward
  22551.           ``\n\\([^\n]*\\)\n\\([^\n]*\\)\n\\([^\n]*\\)\n----------'' nil t)
  22552.     (replace-match ``\n\\1::\\2::\\3'')))
  22553. \end{verbatim}
  22554.  
  22555. \section{Perl}
  22556.  
  22557. \begin{verbatim}
  22558.  
  22559.     #!/usr/bin/perl
  22560.     $/ = "\n----------";      # set record separator
  22561.     while (<>) {        # read a record
  22562.     s!$/$!!;          # remove record terminator
  22563.     s/^\n//;        # trim first line feed
  22564.     s/\n/::/g;        # turn rest into double dolon
  22565.     print "\n";        # new record starts with \n
  22566.     print;            # output current pattern space
  22567.     } 
  22568.  
  22569. # Did you know that the last record in the file will no longer
  22570. # have a terminating newline?  Make sure the others get this right.
  22571. \end{verbatim}
  22572.  
  22573. \section{Tcl}
  22574.  
  22575. \begin{verbatim}
  22576.  
  22577.      set fdIn [open testFile r]
  22578.      set contents [read $fdIn]
  22579.      regsub -all "^\n" $contents "" contents
  22580.      regsub -all "\n" $contents "::" contents
  22581.      regsub -all "::----------::" $contents "\n" contents
  22582.      close $fdIn
  22583.      set fdOut [open testFile w]
  22584.      puts $fdOut $contents nonewline
  22585.      close $fdOut
  22586.      exit
  22587.  
  22588.  
  22589. \end{verbatim}
  22590.  
  22591. \end{enumerate}
  22592.  
  22593.  
  22594. %%% 3. \part {Speed} %%%
  22595.  
  22596. \part {Speed}
  22597.  
  22598.  
  22599. %%% 4. \part {Ease of Use} %%%
  22600.  
  22601. %%% 4.1. \chapter {Documentation/Support} %%%
  22602.  
  22603. \chapter {Documentation/Support}
  22604.  
  22605.  
  22606. \section{Emacs Lisp}
  22607. Excellent. Both for using Emacs and programming Emacs Lisp.
  22608.  
  22609. \section{Perl}
  22610. Excellent. A book is out by Larry Wall called Programming in Perl. The
  22611. manual page is 80 pages typeset. The newsgroup comp.lang.perl is very
  22612. active and helpful and the newsgroup archives are available
  22613. on-line, and come with literally thousands of code snippets and fully
  22614. fledged programs doing more different things than I can begin to
  22615. enumerate.  There is also an excellent quick reference guide, and
  22616. professionally-taught courses for Perl available.
  22617.  
  22618.  
  22619. \section{Python}
  22620. Good. Covers everything but how to extend Python through C.
  22621.  
  22622. \section{Tcl}
  22623. Good. The Tcl book is due out soon.
  22624.  
  22625. \chapter{Program Development}
  22626.  
  22627. \section{Emacs Lisp}
  22628. The best. Has a debugger. Since you are in Emacs, you can immediately
  22629. test whatever you are writing. Documentation on every function and
  22630. variable in memory is available in 2 keypresses. The tags system allows
  22631. you to jump to functions and global variable declarations without
  22632. knowing which file they are in. 
  22633. \section{Perl}
  22634. I would say strong.  To use Perl, you only need to know a little bit to
  22635. start to use it.  The interactive debugger allows you to type any kind of
  22636. Perl code you want and get an immediate answer, as well as providing
  22637. standard sym debugger capabilities such as breakpoints, single-stepping,
  22638. and stack tracebacks.  Other tools available but not included with the
  22639. Perl src kit include profilers, tags generators, cross referencers, and
  22640. tools to assemble large Perl programs using makefiles and a lintlike
  22641. checker.  Other tools provide perl-mode for vi as well as tightly coupling
  22642. the debugger with a slave vi session that autopositions by file and line.
  22643.  
  22644. \section{Python}
  22645. Good. The concept of immutable strings takes some getting used to.
  22646.  
  22647.  
  22648. \section{Tcl}
  22649. The language is very consistent --- every line is
  22650. started with a command which is the name of a Tcl or C function. The
  22651. rest of the line is arguments to the Tcl or C function.
  22652.  
  22653. %%% 4.2. \chapter {Extensibility} %%%
  22654.  
  22655. \chapter{Extensibility}
  22656.  
  22657.  
  22658. When I say extensibility I mean the ability to add a new keyword or data
  22659. type to a language as opposed to adding a new utility.
  22660.  
  22661. \section{Emacs Lisp}
  22662. Writing new lisp functions is only feasible by using the
  22663. already-available lisp functions. To write new lisp functions in C would mean
  22664. re-compiling Emacs every time. 
  22665.  
  22666. \section{Perl}
  22667. You can extend Perl through linking with C routines.  The example
  22668. with the perl kit explains how to do this for the curses library,
  22669. but can be done for many other applications as well.  This is adding
  22670. new function calls.
  22671.  
  22672. What I don't think is easy is changing the perl syntax.
  22673.  
  22674. What you would probably do is define a package and use acccessor
  22675. functions.  I did this to allow perl user's to get at C struct and union
  22676. types to interract with C programs.  A package is semi-reminiscent of a
  22677. C++ class, perhaps best described as a protected namespace with private
  22678. and public data declarations and initialization code, as well as both
  22679. private and public functions.  I wonder how the other languages stack up
  22680. on this kind of thing.
  22681.  
  22682.  
  22683. \section{Python}
  22684. Its possible in C. How to do it in C is not well documented.
  22685.  
  22686. \section{Tcl}
  22687. Its possible and well-docuemented and has been down well by many
  22688. people in C.
  22689.  
  22690. \chapter{Test Suite}
  22691.  
  22692.  
  22693. \section{Emacs Lisp}
  22694. Well, if you compile Emacs then Emacs Lisp will run. This is
  22695. irrelevant criteria for Emacs Lisp.
  22696.  
  22697. \section{Perl}
  22698. Perl comes with an exhaustive test suite.
  22699.  
  22700. \section{Python}
  22701. Exhaustive test suite
  22702. \section{Tcl}
  22703. Exhaustive test suite
  22704.  
  22705.  
  22706. %%% 5. \part {The Future} %%%
  22707.  
  22708. \part {The Future}
  22709. \section {More Languages}
  22710. \section {More Examples and Tests}
  22711. \section {Multiple Computer Language Programming}
  22712.  
  22713.  
  22714. \end{document}
  22715.  
  22716.  
  22717.  
  22718. 
  22719. 
  22720. Received: from uunet.ca by charon.cwi.nl with SMTP
  22721.     id AA23047 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 20:35:22 +0100
  22722. Received: from tsltor by mail.uunet.ca with UUCP id <102196(1)>; Fri, 15 Oct 1993 15:19:14 -0400
  22723. Received: from osprey.teleride.on.ca by falcon.teleride.on.ca with smtp
  22724.     (Smail3.1.26.7 #5) id m0onufC-0000eOC; Fri, 15 Oct 93 15:18 EDT
  22725. Received: by vax.teleride.on.ca (MX V3.0A) id 31278; Fri, 15 Oct 1993 15:16:08
  22726.           EDT
  22727. Sender: <lou@vax.teleride.on.ca>
  22728. Date:     Fri, 15 Oct 1993 15:16:14 -0400
  22729. From: Lou Kates <lou@vax.teleride.on.ca>
  22730. To: python-list@cwi.nl
  22731. Message-Id: <009740F6.B05E1F80.31278@vax.teleride.on.ca>
  22732. Subject: Re: Termcap /curses
  22733.  
  22734. >| Another approach would be  to  develop  a C to Python translator.
  22735. >| That would also be a large amount of  work  and  its  conceivable
  22736. >| that certain features would have to be added to Python to make it
  22737. >| feasible but it would allow one to translate not only the bulk of
  22738. >| the curses source but many other C libraries all in one go.
  22739. >
  22740. >I'm afraid that you would lose the object oriented aspect of Python, which
  22741. >is the most valuable aspect of Python modules that interact with certain
  22742. >facets of POSIX. As an example look at the socket module. If the translation
  22743. >does not allow this kind of abstraction, it would be useless IMHO.
  22744. >
  22745.  
  22746. There are numerous libraries  that  provide  OO encapsulations of 
  22747. originally non-OO libraries.    
  22748.  
  22749. Lou Kates, louk@teleride.on.ca
  22750. 
  22751. 
  22752. Replied: Sat, 16 Oct 1993 18:22:11 +0100
  22753. Replied: "Bill Janssen <janssen@parc.xerox.com> "
  22754. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  22755.     id AA23747 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 21:46:31 +0100
  22756. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11882>; Fri, 15 Oct 1993 13:46:01 PDT
  22757. Received: by holmes.parc.xerox.com id <16134>; Fri, 15 Oct 1993 13:45:54 -0700
  22758. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  22759.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  22760.           Fri, 15 Oct 1993 13:45:53 -0700 (PDT)
  22761. Message-Id: <Mgjkk1EB0KGWJDk5kd@holmes.parc.xerox.com>
  22762. Date:     Fri, 15 Oct 1993 13:45:53 PDT
  22763. Sender: Bill Janssen <janssen@parc.xerox.com>
  22764. From: Bill Janssen <janssen@parc.xerox.com>
  22765. To: Guido.van.Rossum@cwi.nl
  22766. Subject: Re: Python & Sun shared libraries
  22767. In-Reply-To: <9310150951.AA09117=guido@voorn.cwi.nl>
  22768. References: <9310150951.AA09117=guido@voorn.cwi.nl>
  22769.  
  22770. Excerpts from direct: 15-Oct-93 Re: Python & Sun shared lib..
  22771. Guido.van.Rossum@cwi.nl (1273)
  22772.  
  22773. > undefine USE_STDWIN in config.c and you should be all set.  The call
  22774. > to wdone() is not really necessary in the X11 or Mac versions; it *is*
  22775. > needed for the termcap version to restore the tty settings, but that's
  22776. > not likely to be very popular at your site...  (If it is, you can
  22777. > always add a function to the module to make an explicit call to
  22778. > wdone() -- make sure it somehow sabotages wopen() so that after
  22779. > calling wdone() the program can't continue to open windows and crash
  22780. > stdwin...
  22781.  
  22782. Perhaps python should have something like onexit()?  Or perhaps each
  22783. module should have the ability to define `__fini__' on itself, which
  22784. python will call when it exits?
  22785.  
  22786. Bill
  22787.  
  22788.  
  22789. 
  22790. 
  22791. Received: from hermix.markv.com by charon.cwi.nl with SMTP
  22792.     id AA23812 (5.65b/3.11/CWI-Amsterdam); Fri, 15 Oct 1993 21:55:48 +0100
  22793. To: tb06@PL122e.EECS.Lehigh.EDU
  22794. Cc: python-list@cwi.nl
  22795. In-Reply-To: <9310151901.AA00535@PL122e.EECS.Lehigh.EDU> (message from TERRENCE BRANNON on Fri, 15 Oct 93 15:01:32 -0400)
  22796. Subject: Re: [request] Impressive Python Software
  22797. X-Organization: Mark V Systems Ltd.
  22798. X-Address: 16400 Ventura Blvd Suite 303, Encino, Ca, 91436, USA
  22799. X-Phone: +1 818 995 7671 (work), +1 818 995 4267 (fax)
  22800. Date: Fri, 15 Oct 93 13:54:44 PDT
  22801. From: lance@markv.com
  22802. Sender: lance@markv.com
  22803. Message-Id:  <9310151354.aa06225@hermix.markv.com>
  22804. Source-Info:  From (or Sender) name not authenticated.
  22805.  
  22806. I think there are a number of things you left out or mis-stated...
  22807. I will try to go through them one by one here...
  22808.  
  22809.  
  22810.  > Python does not yet have a robust ftp interface like Emacs' ange-ftp nor
  22811.  > does it have an advanced desk top calculator like Emacs's calc. However
  22812.  > it does have STDWIN, an easy-to-use windowing system. 
  22813.  
  22814.  You have not seen ftplib.py then... Very simple to use and fairly complete.
  22815. Also, the 0.9.9 version not only will work with STDWIN but also comes
  22816. with full support for X11R4/Motif.
  22817.  
  22818.  
  22819.  > %%% 2. \part {Power} %%%
  22820.  > %%% 2.1.3. \section {Python} %%%
  22821.  > 
  22822.  > \section {Python}
  22823.  > \begin{enumerate}
  22824.  > \item 
  22825.  > ?? -- Multimedia interface. 
  22826.  > \item 
  22827.  > ?? -- Remote Procedure Call debugger
  22828.  > \item 
  22829.  > texfix -- Crude convert latex to texinfo
  22830.  > \item 
  22831.  > throughput -- measure tcp throughput
  22832.  > \item 
  22833.  > dutree -- format du(1) output at a tree sorted by size
  22834.  > \item 
  22835.  > findlinks -- recursively find links to a given path prefix
  22836.  > \item 
  22837.  > lpwatch -- watch BSD line printer queues
  22838.  > \item 
  22839.  > suff -- sort a list of files by suffix 
  22840.  > \end{enumerate}
  22841.  
  22842.  rsa encryption, www, nntpxmit.py (nntpxmit replacement), and
  22843. I am sure many more.. I am currently writting a multi-line UNIX BBS 
  22844. that is written in Python.
  22845.  
  22846.  > %%% 2.2. \chapter {Graphics} %%%
  22847.  > \section{Python}
  22848.  > Through the use of the STDWIN paradigm, the same source code
  22849.  > can do graphics in the following systems:
  22850.  > 
  22851.  > \begin{enumerate}
  22852.  > \item
  22853.  > X-windows
  22854.  > \item
  22855.  > Macintosh using either Think C 4.02 or MPW C 2.02
  22856.  > \item
  22857.  > Atari ST
  22858.  > \item
  22859.  > DOS
  22860.  > \item
  22861.  > Silicon Graphics SGI workstations
  22862.  > \end{enumerate}
  22863.  > 
  22864.  > This approach allows flexibility but means that no one graphics system's
  22865.  > potential is maximized. 
  22866.  
  22867.  the 0.9.9 version also have full X11R4/Motif support...
  22868.  
  22869.  > %%% 2.3. \chapter {User Interface Building} %%%
  22870.  
  22871.  > \section{Python}
  22872.  > Through the use of the STDWIN paradigm, the same source code
  22873.  > can do graphics in the following systems:
  22874.  > 
  22875.  > \begin{enumerate}
  22876.  > \item
  22877.  > X-windows
  22878.  > \item
  22879.  > Macintosh using either Think C 4.02 or MPW C 2.02
  22880.  > \item
  22881.  > Atari ST
  22882.  > \item
  22883.  > DOS
  22884.  > \item
  22885.  > Silicon Graphics SGI workstations
  22886.  > \end{enumerate}
  22887.  > 
  22888.  > This approach allows flexibility but means that no one graphics system's
  22889.  > potential is maximized. 
  22890.  
  22891.  see section 2.2
  22892.  
  22893.  > %%% 2.4. \chapter {String Handling} %%%
  22894.  
  22895.  > \section{Python}
  22896.  > It has a string module and regexp module. It has all the string
  22897.  > @emph{search} capabilities of Emacs, but since strings are immutable in
  22898.  > Python, it understandably does not have Emacs Lisp's string replace power.
  22899.  > 
  22900.  > \section{Tcl}
  22901.  > Everything in Tcl is a string. It is very easy to map certain
  22902.  > string-intensive applications to Tcl. For example, I wrote a program to
  22903.  > do parallel library database searches in Tcl in about two weeks. Ranking
  22904.  > the 4 languages in terms of how easy it would have been: Tcl, Python,
  22905.  > Emacs, and I cant say about Perl because I gave up on Perl quickly after
  22906.  > buying the book and seeing all those registers and the confusing
  22907.  > context-intensive syntax. 
  22908.  
  22909.  did you try to code your program in Python? or as you just assuming 
  22910. that Tcl would have been easier?
  22911.  
  22912.  > %%% 2.5. \chapter {Process Control} %%%
  22913.  
  22914.  > \section{Python}
  22915.  > You would use pipes to do this in Python.
  22916.  
  22917.  This is not 100% true! You also have the full C library of routines..
  22918. fork(), waitpid(), wait(), system(), pipes, kill(), etc.. 
  22919. they are all in the os and posix modules...
  22920.  
  22921.  > %%% 2.6. \chapter {Sample Programs} %%%
  22922.  
  22923.  \section{Python}
  22924.  \begin{verbatim}
  22925.  
  22926.  #! /usr/local/bin/python
  22927.  import posix
  22928.  print 'There are ', `len(posix.listdir('.'))`, 'files in this directory'
  22929.  
  22930.  \end{verbatim}
  22931.  
  22932.  > \item
  22933.  > A lengthy file has been entered with records of the form:
  22934.  > \begin{verbatim}
  22935.  > <\n>NAME<\n>ADDRESS<\n>PHONE<\n>----------
  22936.  > \end{verbatim}
  22937.  > where \begin{verbatim}<\n>\end{verbatim} represents a line feed and the
  22938.  > \begin{verbatim}----------- \end{verbatim} is used to
  22939.  > separate records. Convert all entries in the file to a new format of
  22940.  > the form:
  22941.  > \begin{verbatim}<\n>NAME::ADDRESS::PHONE}
  22942.  > \end{verbatim}
  22943.  
  22944.  \section{Python}
  22945.  \begin{verbatim}
  22946.  
  22947.  #! /usr/local/bin/python
  22948.  import strop
  22949.  
  22950.  fp = open('testFile','r')
  22951.  lines = fp.readlines()  # read all lines in and seperate on \n's
  22952.  fp.close()
  22953.  fp = open('testFile','w')
  22954.  for indx in range(0,len(lines)-4,4):
  22955.      fp.write('\n'+lines[indx]+'::'+linex[indx+1]+'::'+lines[indx+2])
  22956.  fp.close()
  22957.  
  22958.  \end{verbatim}
  22959.  
  22960.  > %%% 4. \part {Ease of Use} %%%
  22961.  > %%% 4.1. \chapter {Documentation/Support} %%%
  22962.  
  22963.  > \section{Python}
  22964.  > Good. Covers everything but how to extend Python through C.
  22965.  
  22966.  Incorrect. Look at python/misc/EXTENDING 
  22967.  
  22968.  > \chapter{Program Development}
  22969.  > 
  22970.  > \section{Python}
  22971.  > Good. The concept of immutable strings takes some getting used to.
  22972.  
  22973.  The language is VERY regular and very powerful. You have seperate 
  22974. name spaces that allow reuse and an OO design of your applications/scripts.
  22975. There are HUNDREDS of support modules you can import...
  22976.  
  22977.  > %%% 4.2. \chapter {Extensibility} %%%
  22978.  > 
  22979.  > When I say extensibility I mean the ability to add a new keyword or data
  22980.  > type to a language as opposed to adding a new utility.
  22981.  > 
  22982.  > \section{Python}
  22983.  > Its possible in C. How to do it in C is not well documented.
  22984.  
  22985.  It is very easy to add new types (I have added about 20 new types of
  22986. objects to Python both at the C code level as well as in Python code)!
  22987.  
  22988.  
  22989. --
  22990.  
  22991. Lance Ellinghouse           lance@markv.com
  22992.  
  22993. 1231 bit key fingerprint = 56 DA 31 0C 17 51 36 6A  4E D4 E0 11 D9 B8 06 0A
  22994. 1024 bit key fingerprint = 66 2C 75 F2 E9 1C 32 84  3A E3 B0 5E 48 01 4C 37
  22995. You can receive my Public Key by `finger lance@markv.com`
  22996. 
  22997. 
  22998. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  22999.     id AA25094 (5.65b/3.11/CWI-Amsterdam); Sat, 16 Oct 1993 00:02:29 +0100
  23000. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11965>; Fri, 15 Oct 1993 16:01:52 PDT
  23001. Received: by holmes.parc.xerox.com id <16134>; Fri, 15 Oct 1993 16:01:48 -0700
  23002. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  23003.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  23004.           Fri, 15 Oct 1993 16:01:42 -0700 (PDT)
  23005. Message-Id: <IgjmjKEB0KGW5Dk8d0@holmes.parc.xerox.com>
  23006. Date:     Fri, 15 Oct 1993 16:01:42 PDT
  23007. Sender: Bill Janssen <janssen@parc.xerox.com>
  23008. From: Bill Janssen <janssen@parc.xerox.com>
  23009. To: python-list@cwi.nl, Lou Kates <lou@vax.teleride.on.ca>
  23010. Subject: Re: Termcap /curses
  23011. In-Reply-To: <009740EC.69AFD6A0.31251@vax.teleride.on.ca>
  23012. References: <009740EC.69AFD6A0.31251@vax.teleride.on.ca>
  23013.  
  23014. Excerpts from mail: 15-Oct-93 Re: Termcap /curses Lou
  23015. Kates@vax.teleride.o (1221)
  23016.  
  23017. > Another approach would be  to  develop  a C to Python translator.
  23018. > That would also be a large amount of  work  and  its  conceivable 
  23019. > that certain features would have to be added to Python to make it 
  23020. > feasible but it would allow one to translate not only the bulk of 
  23021. > the curses source but many other C libraries all in one go.
  23022.  
  23023. An interesting idea, but I'm afraid there would be a type mismatch.  C
  23024. is essentially an assembly language; Python is somewhat more abstract
  23025. and application-oriented.  There are many different ways of doing
  23026. objects, error signalling, etc., in C, and you'd have to keep pointing
  23027. out what your *particular* object idiom is for it to be *correctly*
  23028. translated to Python.  Similarly for exceptions; you'd have to keep
  23029. pointing out that in this program, *this* is an exception, while in
  23030. *that* program, *that* is an exception.  How would malloc(), free() be
  23031. represented?  I think you'd wind up with something like the output of a
  23032. disassembler.
  23033.  
  23034. It seems to me that the current model of constructing new Python modules
  23035. in C, like stdwin or dbm, is a reasonable solution to the problem of
  23036. using external libraries.
  23037.  
  23038. Bill
  23039.  
  23040.  
  23041.  
  23042. 
  23043. 
  23044. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  23045.     id AA25598 (5.65b/3.11/CWI-Amsterdam); Sat, 16 Oct 1993 00:54:22 +0100
  23046. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11957>; Fri, 15 Oct 1993 16:53:55 PDT
  23047. Received: by holmes.parc.xerox.com id <16134>; Fri, 15 Oct 1993 16:53:51 -0700
  23048. From: Bill Janssen <janssen@parc.xerox.com>
  23049. To: tb06@pl122e.eecs.lehigh.edu
  23050. Subject: Comments on your Survey paper
  23051. Cc: python-list@cwi.nl
  23052. Message-Id: <93Oct15.165351pdt.16134@holmes.parc.xerox.com>
  23053. Date:     Fri, 15 Oct 1993 16:53:39 PDT
  23054.  
  23055. [ Just to admit my biases:  I've hacked GNU Emacs on both
  23056. the C and Elisp level; I've hacked ELK quite a bit, turning
  23057. it into a real shell, as well as embedding it in some
  23058. languages; I've dabbled in both Perl and Tcl; but Python is
  23059. currently my preferred language.  It does pretty much everything
  23060. all these other languages do!
  23061.  
  23062. When I look at an interpreted extension language, I look for the
  23063. following (in no particular order):
  23064.  
  23065.     1)  object system
  23066.     2)  byte compiler
  23067.     3)  regular syntax
  23068.     4)  garbage collector
  23069.     6)  floating point support
  23070.     7)  macros
  23071.     8)  regular expression support
  23072.     9)  unix system call support
  23073.     10) portability (UNIX, Mac, MS-Windows)
  23074.     11) good file system support
  23075.     12) reasonable image size
  23076.     13) threads
  23077.  
  23078. because I know that sooner or later, I'll need them all. ]
  23079.  
  23080. OK, comments:
  23081.  
  23082. Page 6: You say that you're working on extracting the elisp
  23083. interpreter.  I'd say, don't bother.  ELK has already done a great
  23084. job, with the following advantages over elisp: 1) a standard language,
  23085. with books available, and 2) dynamic loading of new object code.
  23086.  
  23087. Page 6: Note that all the advantages you ascribe to Perl are also
  23088. in Python, except that Python tends to do it better!
  23089.  
  23090. Page 7:  There are better FTP sites in the US for Python:
  23091.   gatekeeper.dec.com    16.1.0.2        /pub/plan/python/cwi
  23092.   ftp.uu.net        192.48.96.9        /languages/python
  23093.   wuarchive.wustl.edu    128.252.135.4        /pub
  23094.  
  23095. Check out lib/python/ftplib.py.
  23096.  
  23097. Page 14:  In addition to STDWIN, Python can manipulate X via Motif,
  23098. and of course it can do the same kind of things that you mention under
  23099. the Perl section.  I am using it with EZD, Joel Bartlett's very nice
  23100. WAFE-style system (very nice, check it out!).
  23101.  
  23102. Page 18: Check out Python's regsub module.  It arguably gives you all
  23103. the string replace power of Emacs.  Basically the same as Tcl's, I
  23104. believe.
  23105.  
  23106. Page 19:  Python's process control is at least as strong as Perl's.
  23107. In addition, it supports threads (!), so that some of the operations
  23108. you have to do in another process, using Tcl or Perl, you can do
  23109. in another thread, in Python.
  23110.  
  23111. Page 21:  List directories:
  23112.  
  23113.     #!/usr/bin/python
  23114.     import posix
  23115.     print len(posix.listdir('.'))
  23116.  
  23117. None of your hello world examples actually work on the Macintosh,
  23118. do they?  This one (in Python) does (as well as X windows):
  23119.  
  23120. Hello, World:
  23121.  
  23122.     #!/usr/bin/python
  23123.     import stdwin
  23124.     stdwin.message('Hello, World!')
  23125.  
  23126. Hello, Bob (I think; I didn't actually try it):
  23127.  
  23128.     #!/usr/bin/python
  23129.  
  23130.     def sub_in_file(file):
  23131.         import regsub
  23132.         import string
  23133.  
  23134.         seen = None
  23135.         fp = open(file, 'r+')
  23136.         lines = fp.readlines()
  23137.         fp.seek(0, 0)
  23138.         for line in lines:
  23139.             if seen:
  23140.                 regsub.gsub('Hello Bob', 'Hi James', line)
  23141.             else:
  23142.                 seen = (string.find (line, 'Hello Bob') >= 0) 
  23143.             fp.write(line)
  23144.  
  23145.     import sys
  23146.  
  23147.     sub_in_file(sys.argv[1])
  23148.  
  23149. Page 27: The documents EMBEDDING and EXTENDING (in the src/misc
  23150. directory, which I agree is misleading) describe both how to add new C
  23151. primitives to Python, and how to embed it as the extension language
  23152. for some larger program.
  23153.  
  23154. Page 28: Note that there is a GNU Emacs mode for Python, as well as a
  23155. special subprocess mode for it.  There are a couple of debuggers
  23156. shipped with the Python library, one windowing and one
  23157. command-line-like.
  23158.  
  23159. Page 30: See my comment on page 27.  Note that unlike Perl, new Python
  23160. modules written in C can be dynamically loaded into a running
  23161. interpreter.  You don't need to relink the image.  Adding a new
  23162. datatype is very easy.  Modifying the syntax ("adding a new keyword")
  23163. doesn't seem very easy.  There could be a macro package...
  23164.  
  23165. Bill
  23166. 
  23167. 
  23168. Replied: Mon, 18 Oct 1993 10:13:52 +0100
  23169. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> python-list"
  23170. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  23171.     id AA05113 (5.65b/3.11/CWI-Amsterdam); Sat, 16 Oct 1993 23:37:24 +0100
  23172. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa18332;
  23173.           16 Oct 93 18:37 EDT
  23174. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  23175.     id AA15491; Sat, 16 Oct 1993 18:37:13 -0400
  23176. Date: Sat, 16 Oct 1993 18:37:13 -0400
  23177. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  23178. Message-Id: <199310162237.AA15491@elvis.med.Virginia.EDU>
  23179. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  23180. To: lance@markv.com, tb06@pl122e.eecs.lehigh.edu
  23181. Subject: fetch - a simple function using python's ftplib
  23182. Cc: python-list@cwi.nl
  23183.  
  23184.  
  23185. I hadn't noticed ftplib was even there until it came up on the list.
  23186. So I hacked out a fetch function. The *intention* was to handle 
  23187. URL's and/or the  pathnames in T.Brannon's paper, but I didn't have 
  23188. either at hand when I wrote this, so instead, it takes a pathname 
  23189. of the form:   
  23190.     remote.host:/path/filename 
  23191. and by default it will copy (binary) filename into local currect directory.
  23192.  
  23193. I could have hacked in a strip of the "anonymous@" part, but since 
  23194. the example didn't show the format used if a password was also 
  23195. needed, I didn't bother to do it. Maybe if I dig out a copy of the
  23196. URL format, I'll do something else with it. But then, maybe that's 
  23197. already in demo/www/wwwlib.py. Well - I wanted to try out the ftplib
  23198. routines anyway - I need to write a program that backups up PC's 
  23199. thru NCSA Telnet's FTP server to unix tape. That has been on my
  23200. wish list, but I haven't done anything about it - now that I know
  23201. ftplib is there, I'll probably give it a try when I have a bit of
  23202. spare time. 
  23203.  
  23204. The error handling is not as clean and neat as I would probaly 
  23205. want in a final version. This has been minimally tested. 
  23206. ( and not on anything that refuses connections --- I'm relying 
  23207.  that the FTP class methods will do the right thing. ) 
  23208.  
  23209.  
  23210. There is a question for Guido (or some other master of python internals)
  23211. burried in the code: When I moved mt test code into a test function 
  23212. ( so that I could have some cleanup - otherwise when I types 'q' to 
  23213. more, my terminal got zonked! ) and out of the modules global scope, 
  23214. I had to add the "global" declaration - otherwise I got a NameError. 
  23215. I suppose this is a subtle effect of dynamic scoping and the way the
  23216. function is used as a callback function in another scope. But I would
  23217. welcome it if someone can explain what's going on in more detail. 
  23218.  
  23219.  
  23220.  
  23221. - Steve Majewski       (804-982-0831)      <sdm7g@Virginia.EDU>
  23222. - UVA Department of Molecular Physiology and Biological Physics
  23223.  
  23224. ------------------------
  23225. #!/usr/local/bin/python
  23226. #
  23227. # fetch : a simple higher level function to python's ftplib
  23228. #
  23229. # given a pathname of format: host.part:/path/filename
  23230. # 'fetch( pathname )' will fetch pathname into current local directory
  23231. # 'fetch( pathname, open( FNAME, 'w').write )'  will copy remote pathname 
  23232. #            into local FNAME, and
  23233. # 'fetch( pathname, func ) will send blocks pathname to output function func.
  23234. # ( see test examples at end )
  23235. # other option arg is one of:
  23236. #     'ascii', 'text', 'mode=ascii', 'mode=text' 
  23237. # which change the transfer mode from binary to text
  23238. # ( note that retrlines strips tailing newlines ) 
  23239. # options to be added later:
  23240. #    FTP().login() supports optional args for USER & PASSWD -
  23241. #    add check for optional args "user=" and "pass=" to fetch.
  23242. #
  23243. #
  23244. # shell usage:
  23245. #     fetch.py  remotepathnames... 
  23246. #
  23247. #               - S.D.Majewski/UVA    <sdm7g@Virginia.EDU> 
  23248.  
  23249.  
  23250. from ftplib import FTP
  23251. import string
  23252. import posixpath
  23253.  
  23254.  
  23255.  
  23256. def null(): pass
  23257. FUNC_TYPES = ( type( null ), type( type ) ) 
  23258. # to include both <type 'function'> and <type 'builtin_function_or_method'>
  23259.  
  23260. TEXT_MODES = ( 'text', 'ascii', 'mode=text', 'mode=ascii' ) 
  23261.  
  23262. def fetch( fname, *opts ):
  23263.     mode = 'bin'        # default transfer mode
  23264.     func = None        
  23265.     if opts :
  23266.        for arg in opts:
  23267.         if type( arg ) in FUNC_TYPES :    func = arg
  23268.         elif arg in TEXT_MODES :     mode = 'text' 
  23269.     host, dir, file = parse( fname )
  23270.     if not func : func = open( file, 'w' ).write
  23271.     ftp = FTP().init( host )
  23272.     ftp.login()
  23273.     ftp.cwd( dir )
  23274.     print ftp.nlst( file ), 'mode='+mode    # this can be removed 
  23275.     if mode == 'text' :
  23276.         try:
  23277.           ftp.retrlines( 'RETR ' + file, func )
  23278.         except IOError:
  23279.           ftp.abort()
  23280.           ftp.quit()
  23281.           raise IOError
  23282.     elif mode == 'bin' : 
  23283.         try:
  23284.           ftp.retrbinary( 'RETR '+ file, func, 512 )
  23285.         except IOError:
  23286.           ftp.abort()
  23287.           ftp.quit()
  23288.           raise IOError
  23289.     ftp.quit()
  23290.  
  23291.  
  23292. def parse( fname ):
  23293.     list = string.splitfields( fname, ':' )
  23294.     if len( list ) <> 2 : raise 'NoHostPart' 
  23295.     host = list[0]
  23296.     dir, file = posixpath.split( list[1] )
  23297.     return ( host, dir, file )
  23298.  
  23299.  
  23300. # example usage 
  23301.  
  23302. from posix import popen
  23303.  
  23304. def test1( ):
  23305.     path = 'uvaarpa.virginia.edu:/pub/hosts' 
  23306.     fetch( path )
  23307.  
  23308.  
  23309. # "global m" appears to be necessary because mwrite callback 
  23310. # function is called in a different context from the one
  23311. # in which it is defined. Without it,  fetch will raise a 
  23312. # NameError exception. ( The wonders of Dynamic scoping? ) 
  23313.  
  23314. def test2():
  23315.     global m
  23316.     m = popen( 'more', 'w' )
  23317.     def mwrite( line ): m.write( line + '\n' )
  23318.     try: 
  23319.       fetch( 'uvaarpa.virginia.edu:/pub/hosts', mwrite, 'text' ) 
  23320.     finally: m.close()
  23321.  
  23322. def test3():
  23323.     z = popen( 'zcat | more', 'w' )
  23324.     try:
  23325.       fetch( 'uvaarpa.virginia.edu:/pub/rfc/rfc822.Z', z.write  ) 
  23326.     finally: z.close()
  23327.  
  23328.  
  23329. import sys
  23330.  
  23331. if sys.argv[1:] : 
  23332.    for file in sys.argv[1:] :
  23333.        fetch( file )
  23334.  
  23335. # ---------- end fetch.py
  23336.  
  23337. 
  23338. 
  23339. Received: from Sun.COM by charon.cwi.nl with SMTP
  23340.     id AA04591 (5.65b/3.11/CWI-Amsterdam); Mon, 18 Oct 1993 23:06:57 +0100
  23341. Received: from Eng.Sun.COM (zigzag.Eng.Sun.COM) by Sun.COM (4.1/SMI-4.1)
  23342.     id AA12025; Mon, 18 Oct 93 15:06:52 PDT
  23343. Received: from cici.Eng.Sun.COM by Eng.Sun.COM (4.1/SMI-4.1)
  23344.     id AA01203; Mon, 18 Oct 93 15:06:42 PDT
  23345. Received: from manjushri.Eng.Sun.COM by cici.Eng.Sun.COM (5.0/SMI-SVR4)
  23346.     id AA06739; Mon, 18 Oct 1993 15:06:53 +0800
  23347. Date: Mon, 18 Oct 1993 15:06:53 +0800
  23348. From: Rafael.Bracho@Eng.Sun.COM (Rafael Bracho)
  23349. Message-Id: <9310182206.AA06739@cici.Eng.Sun.COM>
  23350. To: python-list@cwi.nl
  23351. Subject: Writing classes in C
  23352. X-Sun-Charset: US-ASCII
  23353. Content-Length: 228
  23354.  
  23355. Hi,
  23356.  
  23357. I'd like to write a module in C which defines a class, with at least
  23358. some of its methods executing in C.  Is it possible to define classes
  23359. in C where some (or all) of its methods execute C functions?
  23360.  
  23361. Thanks,
  23362.  
  23363.                     -Rafael
  23364. 
  23365. 
  23366. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  23367.     id AA20426 (5.65b/3.11/CWI-Amsterdam); Mon, 18 Oct 1993 08:57:10 +0100
  23368. Received: by voorn.cwi.nl with SMTP
  23369.     id AA14740 (5.65b/3.8/CWI-Amsterdam); Mon, 18 Oct 1993 08:57:10 +0100
  23370. Message-Id: <9310180757.AA14740=guido@voorn.cwi.nl>
  23371. To: gow@asami.med.ge.com
  23372. Cc: python-list@cwi.nl
  23373. Subject: Re: import restrictions 
  23374. In-Reply-To: Your message of "Mon, 18 Oct 1993 16:37:00 MET."
  23375.              <9310180737.AA03216@asami.asami> 
  23376. From: Guido.van.Rossum@cwi.nl
  23377. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23378. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23379. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23380. Date: Mon, 18 Oct 1993 08:57:09 +0100
  23381. Sender: Guido.van.Rossum@cwi.nl
  23382.  
  23383. > One problem I've been having is that once I have imported
  23384. > a file of definitions into a python session I can't seem
  23385. > to get rid of it.  When I'm editing a script I'd like
  23386. > to have python going in another window, edit the script,
  23387. > re-import it into python, and test it.  It seems, however,
  23388. > that even if I explicitly delete the script's module from 
  23389. > my python session symbol table, the script file is not
  23390. > re-read/re-interpreted when I import it into the python 
  23391. > session again.
  23392.  
  23393. This is intentional -- when you import a module, Python remembers that
  23394. it has imported it so that if you import it again (usually from
  23395. another module) it won't be parsed, compiled and initialize again.
  23396.  
  23397. For the situation you are having, however, you can use the reload()
  23398. built-in function, which forces reparsing etc. of the module.  Note
  23399. that the syntax is
  23400.     reload(expression)
  23401. where the expression must evaluate to a module object; i.e. you must
  23402. already have imported the module once.  Note that reload() does not
  23403. recursively reload modules imported by the reloaded module; you will
  23404. have to do that yourself if it is necessary.
  23405.  
  23406. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23407. 
  23408. 
  23409. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  23410.     id AA21680 (5.65b/3.11/CWI-Amsterdam); Mon, 18 Oct 1993 10:13:53 +0100
  23411. Received: by voorn.cwi.nl with SMTP
  23412.     id AA14925 (5.65b/3.8/CWI-Amsterdam); Mon, 18 Oct 1993 10:13:53 +0100
  23413. Message-Id: <9310180913.AA14925=guido@voorn.cwi.nl>
  23414. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  23415. Cc: python-list@cwi.nl
  23416. Subject: Re: fetch - a simple function using python's ftplib 
  23417. In-Reply-To: Your message of "Sat, 16 Oct 1993 18:37:13 MET."
  23418.              <199310162237.AA15491@elvis.med.Virginia.EDU> 
  23419. From: Guido.van.Rossum@cwi.nl
  23420. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23421. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23422. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23423. Date: Mon, 18 Oct 1993 10:13:53 +0100
  23424. Sender: Guido.van.Rossum@cwi.nl
  23425.  
  23426. > I hadn't noticed ftplib was even there until it came up on the list.
  23427. > So I hacked out a fetch function. The *intention* was to handle 
  23428. > URL's and/or the  pathnames in T.Brannon's paper, [...]
  23429.  
  23430. Thanks!  (There is indeed URL parsing support in demo/www/wwwlib.py
  23431. and/or elsewhere in demo/www.)
  23432.  
  23433. > There is a question for Guido (or some other master of python internals)
  23434. > burried in the code: When I moved mt test code into a test function 
  23435. > ( so that I could have some cleanup - otherwise when I types 'q' to 
  23436. > more, my terminal got zonked! ) and out of the modules global scope, 
  23437. > I had to add the "global" declaration - otherwise I got a NameError. 
  23438. > I suppose this is a subtle effect of dynamic scoping and the way the
  23439. > function is used as a callback function in another scope. But I would
  23440. > welcome it if someone can explain what's going on in more detail. 
  23441. [referring to:]
  23442. > # "global m" appears to be necessary because mwrite callback 
  23443. > # function is called in a different context from the one
  23444. > # in which it is defined. Without it,  fetch will raise a 
  23445. > # NameError exception. ( The wonders of Dynamic scoping? ) 
  23446. > def test2():
  23447. >     global m
  23448. >     m = popen( 'more', 'w' )
  23449. >     def mwrite( line ): m.write( line + '\n' )
  23450. >     try: 
  23451. >       fetch( 'uvaarpa.virginia.edu:/pub/hosts', mwrite, 'text' ) 
  23452. >     finally: m.close()
  23453.  
  23454. This is because nested function definitions don't have access to the
  23455. local variables of the surrounding block -- only to the globals of the
  23456. containing module.  This is done so that lookup of globals doesn't
  23457. have to walk a chain of dictionaries -- as in C, there are just two
  23458. nested scopes: locals and globals (and beyond this, built-ins).
  23459. Therefore, nested functions have only a limited use.  This was a
  23460. deliberate decision, based upon experience with languages allowing
  23461. arbitraries nesting such as Pascal and both Algols -- code with too
  23462. many nested scopes is about as readable as code with too many GOTOs.
  23463. And, of course, in Python, the "proper" way is to use an
  23464. object-oriented programming style:
  23465.  
  23466. def test2():
  23467.     class C:
  23468.       def __init__(self, m ): self.m = m
  23469.       def write( self, line ): self.m.write( line + '\n' )
  23470.       def close( self ): self.m.close()
  23471.     x = C( popen( 'more', 'w' ) )
  23472.     try: 
  23473.       fetch( 'uvaarpa.virginia.edu:/pub/hosts', x.write, 'text' ) 
  23474.     finally: x.close()
  23475.  
  23476. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23477. 
  23478. 
  23479. Replied: Mon, 18 Oct 1993 08:57:08 +0100
  23480. Replied: "gow@asami.med.ge.com python-list"
  23481. Received: from gemsgw.med.ge.com by charon.cwi.nl with SMTP
  23482.     id AA20202 (5.65b/3.11/CWI-Amsterdam); Mon, 18 Oct 1993 08:36:43 +0100
  23483. Received: from gemed.med.ge.com by gemsgw.med.ge.com (4.1/GEMS-1.1)
  23484.     id AA24679; Mon, 18 Oct 93 02:39:59 CDT
  23485. Received: from anri.yms by gemed.med.ge.com (4.1/SMI-4.1)
  23486.     id AA13094; Mon, 18 Oct 93 02:36:13 CDT
  23487. Received: from asami.asami by anri.yms (4.1/SMI-4.1)
  23488.     id AA18904; Mon, 18 Oct 93 16:35:39 JST
  23489. Received: from hakkou.asami by asami.asami (4.1/SMI-4.1)
  23490.     id AA03216; Mon, 18 Oct 93 16:37:00 JST
  23491. Date: Mon, 18 Oct 93 16:37:00 JST
  23492. From: gow@asami.med.ge.com
  23493. Message-Id: <9310180737.AA03216@asami.asami>
  23494. To: python-list%cwi.nl%gemed@anri.med.ge.com
  23495. Subject: import restrictions
  23496.  
  23497.  
  23498. One problem I've been having is that once I have imported
  23499. a file of definitions into a python session I can't seem
  23500. to get rid of it.  When I'm editing a script I'd like
  23501. to have python going in another window, edit the script,
  23502. re-import it into python, and test it.  It seems, however,
  23503. that even if I explicitly delete the script's module from 
  23504. my python session symbol table, the script file is not
  23505. re-read/re-interpreted when I import it into the python 
  23506. session again.
  23507.  
  23508. Is there something I'm doing wrong?  Is it that I'm in 
  23509. Japan, with it's infamous "import restrictions" :^) ? 
  23510. Or is this the way python (0.98) works?
  23511.  
  23512.     Ed
  23513. 
  23514. 
  23515. Received: from gateway.sequent.com by charon.cwi.nl with SMTP
  23516.     id AA04752 (5.65b/3.11/CWI-Amsterdam); Mon, 18 Oct 1993 23:27:19 +0100
  23517. Received: from [138.95.9.34] by gateway.sequent.com (5.61/1.34)
  23518.     id AA23929; Mon, 18 Oct 93 15:27:50 -0700
  23519. Received: from ushqgw1.sequent.com by relay1.sequent.com (5.65/crg/11)
  23520.     id AA17963; Mon, 18 Oct 93 15:34:17 -0700
  23521. Received: by ushqgw.sequent.com with Microsoft Mail
  23522.     id <2CC317A7@ushqgw.sequent.com>; Mon, 18 Oct 93 15:24:39 PDT
  23523. From: "Jaap Vermeulen (jaap)" <jaap@sequent.com>
  23524. To: python-list <python-list@cwi.nl>,
  23525.         "Rafael.Bracho" <Rafael.Bracho@Eng.Sun.COM>
  23526. Subject: RE: Writing classes in C
  23527. Date: Mon, 18 Oct 93 15:23:00 PDT
  23528. Message-Id: <2CC317A7@ushqgw.sequent.com>
  23529. Encoding: 11 TEXT
  23530. X-Mailer: Microsoft Mail V3.0
  23531.  
  23532.  
  23533.  
  23534. | I'd like to write a module in C which defines a class, with at least
  23535. | some of its methods executing in C.  Is it possible to define classes
  23536. | in C where some (or all) of its methods execute C functions?
  23537.  
  23538. Just make it a built-in object, such as fileobject. If you need to access it 
  23539. using a user-defined class, just write a class wrapper around the built-in 
  23540. object.
  23541.  
  23542.      -Jaap-
  23543. 
  23544. 
  23545. Replied: Thu, 21 Oct 1993 10:18:33 +0100
  23546. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list"
  23547. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  23548.     id AA22159 (5.65b/3.11/CWI-Amsterdam); Thu, 21 Oct 1993 07:28:17 +0100
  23549. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <12265>; Wed, 20 Oct 1993 23:28:06 PDT
  23550. Received: by holmes.parc.xerox.com id <16134>; Wed, 20 Oct 1993 23:28:02 -0700
  23551. From: Bill Janssen <janssen@parc.xerox.com>
  23552. To: python-list@cwi.nl
  23553. Subject: obtaining the reversal of a sequence?
  23554. Message-Id: <93Oct20.232802pdt.16134@holmes.parc.xerox.com>
  23555. Date:     Wed, 20 Oct 1993 23:27:57 PDT
  23556.  
  23557. I've encountered the problem where I'd like to have a sequence that is
  23558. traversed in both directions equally frequently.  It's a display list, and
  23559. is traversed from back to front, to paint the window, and from front to
  23560. back, to find the innermost element enclosing a point.
  23561.  
  23562. Clearly, the ``for foo in x'' construct works well for one of the two
  23563. cases, but what's the efficient way to traverse the list in reverse order?
  23564. The best I can come up with is:
  23565.  
  23566.     tmp = list[:]
  23567.     tmp.reverse()
  23568.     for x in tmp:
  23569.         blah...
  23570.  
  23571. and that's so inefficient I believe there must be some trick tucked away
  23572. to make this easier.
  23573.  
  23574. Bill
  23575.  
  23576. 
  23577. 
  23578. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  23579.     id AA24624 (5.65b/3.11/CWI-Amsterdam); Thu, 21 Oct 1993 10:18:33 +0100
  23580. Received: by voorn.cwi.nl with SMTP
  23581.     id AA24516 (5.65b/3.8/CWI-Amsterdam); Thu, 21 Oct 1993 10:18:33 +0100
  23582. Message-Id: <9310210918.AA24516=guido@voorn.cwi.nl>
  23583. To: Bill Janssen <janssen@parc.xerox.com>
  23584. Cc: python-list@cwi.nl
  23585. Subject: Re: obtaining the reversal of a sequence? 
  23586. In-Reply-To: Your message of "Wed, 20 Oct 1993 23:27:57 MDT."
  23587.              <93Oct20.232802pdt.16134@holmes.parc.xerox.com> 
  23588. From: Guido.van.Rossum@cwi.nl
  23589. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23590. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23591. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23592. Date: Thu, 21 Oct 1993 10:18:33 +0100
  23593. Sender: Guido.van.Rossum@cwi.nl
  23594.  
  23595. > I've encountered the problem where I'd like to have a sequence that is
  23596. > traversed in both directions equally frequently.  It's a display list, and
  23597. > is traversed from back to front, to paint the window, and from front to
  23598. > back, to find the innermost element enclosing a point.
  23599. > Clearly, the ``for foo in x'' construct works well for one of the two
  23600. > cases, but what's the efficient way to traverse the list in reverse order?
  23601. > The best I can come up with is:
  23602. >     tmp = list[:]
  23603. >     tmp.reverse()
  23604. >     for x in tmp:
  23605. >         blah...
  23606. > and that's so inefficient I believe there must be some trick tucked away
  23607. > to make this easier.
  23608.  
  23609. Hmm, I don't think there's a trick for this in the language.  You
  23610. could reverse the list in place and reverse it back after the loop --
  23611. reverse() is actually pretty fast compared to doing anything in
  23612. Python, and it's certainly faster than the code given here: the
  23613. list[:] operation will take more time than an extra reverse() call
  23614. because (a) it allocates two new blocks of memory, (b) it has to
  23615. increment the reference counts of all list items, and (c) it has to
  23616. undo all that when you're done.
  23617.  
  23618. Alternatively, if you can't afford to reverse the list in place
  23619. because other users of it may get confused, you can construct the
  23620. reverse index sequence manually:
  23621.  
  23622.     i = len(list)
  23623.     while i > 0:
  23624.         i = i-1
  23625.         x = list[i]
  23626.         blah...
  23627.  
  23628. Using range() will create a list containing lots of new integer
  23629. objects and thus be the slowest of all, unless the list changes
  23630. infrequently and you can save a permanent copy of it -- but that's a
  23631. maintenance nightmare.
  23632.  
  23633. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23634. 
  23635. 
  23636. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  23637.     id AA13519 (5.65b/3.11/CWI-Amsterdam); Fri, 22 Oct 1993 09:02:29 +0100
  23638. Received: by voorn.cwi.nl with SMTP
  23639.     id AA27058 (5.65b/3.8/CWI-Amsterdam); Fri, 22 Oct 1993 09:02:29 +0100
  23640. Message-Id: <9310220802.AA27058=guido@voorn.cwi.nl>
  23641. To: Bill Janssen <janssen@parc.xerox.com>
  23642. Cc: python-list@cwi.nl
  23643. Subject: Re: obtaining the reversal of a sequence? 
  23644. In-Reply-To: Your message of "Thu, 21 Oct 1993 12:11:13 MDT."
  23645.              <kglhvFgB0KGWI2rS9G@holmes.parc.xerox.com> 
  23646. From: Guido.van.Rossum@cwi.nl
  23647. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23648. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23649. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23650. Date: Fri, 22 Oct 1993 09:02:28 +0100
  23651. Sender: Guido.van.Rossum@cwi.nl
  23652.  
  23653. Bill Janssen writes:
  23654.  
  23655. > It occurs to me that the compiler could probably generate optimized code
  23656. > in the case where it sees the statement
  23657. >     for <ident> in range(<expression>):
  23658. > The list result of range() never really needs to exist, in this case, no?
  23659.  
  23660. Well the compiler isn't very good at recognizing calls to built-in
  23661. functions ('range' could be a local identifier with a different
  23662. meaning).  But someone else proposed that range() return a new object
  23663. type that behaves like a sequence but doesn't store all its elements,
  23664. just returns the one you ask for.
  23665.  
  23666. I am beginning to like this solution.  It would not be 100 percent
  23667. compatible, since uses of range() in other contexts would work
  23668. differently or not at all (e.g. you can't initialize a list with a
  23669. range and then remove items from it) but those uses would be a far
  23670. minority.
  23671.  
  23672. An alternative solution, used in ABC, would be to have an efficient
  23673. alternative representation of list objects consisting of ranges.
  23674. Unfortunately this would complicate the implementation of all list
  23675. operations, so I'm not in favor of it, even though it would be
  23676. marginally cleaner for the user.
  23677.  
  23678. Any other opinions?
  23679.  
  23680. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23681. 
  23682. 
  23683. To: Bill Janssen <janssen@parc.xerox.com>
  23684. cc: python-list
  23685. Subject: Re: obtaining the reversal of a sequence? 
  23686. In-reply-to: Your message of "Thu, 21 Oct 1993 12:11:13 MDT."
  23687.              <kglhvFgB0KGWI2rS9G@holmes.parc.xerox.com> 
  23688. From: Guido.van.Rossum@cwi.nl
  23689. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23690. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23691. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23692. Date: Fri, 22 Oct 1993 09:02:28 +0100
  23693. Sender: guido
  23694.  
  23695. Bill Janssen writes:
  23696.  
  23697. > It occurs to me that the compiler could probably generate optimized code
  23698. > in the case where it sees the statement
  23699. >     for <ident> in range(<expression>):
  23700. > The list result of range() never really needs to exist, in this case, no?
  23701.  
  23702. Well the compiler isn't very good at recognizing calls to built-in
  23703. functions ('range' could be a local identifier with a different
  23704. meaning).  But someone else proposed that range() return a new object
  23705. type that behaves like a sequence but doesn't store all its elements,
  23706. just returns the one you ask for.
  23707.  
  23708. I am beginning to like this solution.  It would not be 100 percent
  23709. compatible, since uses of range() in other contexts would work
  23710. differently or not at all (e.g. you can't initialize a list with a
  23711. range and then remove items from it) but those uses would be a far
  23712. minority.
  23713.  
  23714. An alternative solution, used in ABC, would be to have an efficient
  23715. alternative representation of list objects consisting of ranges.
  23716. Unfortunately this would complicate the implementation of all list
  23717. operations, so I'm not in favor of it, even though it would be
  23718. marginally cleaner for the user.
  23719.  
  23720. Any other opinions?
  23721.  
  23722. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23723. 
  23724. 
  23725. Received: from uunet.ca by charon.cwi.nl with SMTP
  23726.     id AA15402 (5.65b/3.11/CWI-Amsterdam); Fri, 22 Oct 1993 11:13:35 +0100
  23727. Received: from tsltor by mail.uunet.ca with UUCP id <100970(5)>; Fri, 22 Oct 1993 06:13:18 -0400
  23728. Received: from osprey.teleride.on.ca by falcon.teleride.on.ca with smtp
  23729.     (Smail3.1.26.7 #5) id m0oqIZG-0000eOC; Fri, 22 Oct 93 05:13 EDT
  23730. Received: by vax.teleride.on.ca (MX V3.0A) id 32455; Fri, 22 Oct 1993 05:11:48
  23731.           EDT
  23732. Sender: <lou@vax.teleride.on.ca>
  23733. Date:     Fri, 22 Oct 1993 05:12:14 -0400
  23734. From: Lou Kates <lou@vax.teleride.on.ca>
  23735. To: Guido.van.Rossum@cwi.nl
  23736. Cc: python-list@cwi.nl
  23737. Message-Id: <00974622.789D0DA0.32455@vax.teleride.on.ca>
  23738. Subject: Re: obtaining the reversal of a sequence?
  23739.  
  23740. >> It occurs to me that the compiler could probably generate optimized code
  23741. >> in the case where it sees the statement
  23742. >>
  23743. >>     for <ident> in range(<expression>):
  23744. >>
  23745. >> The list result of range() never really needs to exist, in this case, no?
  23746. >
  23747. >Well the compiler isn't very good at recognizing calls to built-in
  23748. >functions ('range' could be a local identifier with a different
  23749. >meaning).  But someone else proposed that range() return a new object
  23750. >type that behaves like a sequence but doesn't store all its elements,
  23751. >just returns the one you ask for.
  23752. >
  23753.  
  23754. Presumably  this  is not the only instance where lazy  evaluation 
  23755. could apply to Python.
  23756.  
  23757. Also, the Icon language is something to  look  at  here since its 
  23758. generation and lazy evaluation of infinite sequences is  close to 
  23759. what is being discussed here.
  23760.  
  23761. Lou Kates, louk@teleride.on.ca
  23762. 
  23763. 
  23764. Received: from anjer.cwi.nl by charon.cwi.nl with SMTP
  23765.     id AA14555 (5.65b/3.11/CWI-Amsterdam); Fri, 22 Oct 1993 10:19:39 +0100
  23766. Received: by anjer.cwi.nl with SMTP
  23767.     id AA01355 (5.65b/3.8/CWI-Amsterdam); Fri, 22 Oct 1993 10:19:39 +0100
  23768. Message-Id: <9310220919.AA01355=soede@anjer.cwi.nl>
  23769. To: Guido.van.Rossum@cwi.nl
  23770. Cc: python-list@cwi.nl
  23771. Subject: Re: obtaining the reversal of a sequence? 
  23772. In-Reply-To: Your message of "Fri, 22 Oct 1993 09:02:28 MET."
  23773.              <9310220802.AA27058=guido@voorn.cwi.nl> 
  23774. Date: Fri, 22 Oct 1993 10:19:38 +0100
  23775. From: Dirk Soede <Dirk.Soede@cwi.nl>
  23776.  
  23777. >meaning).  But someone else proposed that range() return a new object
  23778. >type that behaves like a sequence but doesn't store all its elements,
  23779. >just returns the one you ask for.
  23780.  
  23781. This is the same as in Smalltalk. There a loop is actually a method of a
  23782. Sequence which executes the code of the loop on each Sequence element. The
  23783. Sequence is only accessed through `first' and `next'. So it can also choose
  23784. to generate the next item only when requested. This sounds very clean to
  23785. me.
  23786.  
  23787. You could also have a reverse loop when Sequences would have methods last
  23788. and previous.
  23789.  
  23790. >I am beginning to like this solution.  It would not be 100 percent
  23791. >compatible, since uses of range() in other contexts would work
  23792. >differently or not at all (e.g. you can't initialize a list with a
  23793. >range and then remove items from it) but those uses would be a far
  23794.  
  23795. Maybe when a range object is copied it should have a copy method, which
  23796. returns a real list with all elements.
  23797.  
  23798. Dirk Soede
  23799.  
  23800. Centre for Mathematics & Computer Science (CWI),
  23801. Kruislaan 413, 1098 SJ Amsterdam, The Netherlands.
  23802. Email:soede@cwi.nl, Tel: +31-20-592 4009
  23803.  
  23804. 
  23805. 
  23806. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  23807.     id AA00526 (5.65b/3.11/CWI-Amsterdam); Fri, 22 Oct 1993 23:02:41 +0100
  23808. Received: from galen.med.virginia.edu by uvaarpa.virginia.edu id aa19812;
  23809.           22 Oct 93 18:02 EDT
  23810. Received: by galen.med.Virginia.EDU (5.67a8/1.34)
  23811.     id AA46522; Fri, 22 Oct 1993 18:02:34 -0400
  23812. Date: Fri, 22 Oct 1993 18:02:34 -0400
  23813. From: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  23814. Message-Id: <199310222202.AA46522@galen.med.Virginia.EDU>
  23815. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  23816. To: python-list@cwi.nl
  23817. Subject: the proper name for dictionaries,maps,associative-arrays,tables...
  23818.  
  23819.  
  23820. There has been some discussion in comp.language.perl on the 
  23821. best or proper name for dictionaries/associative-arrays/maps/
  23822. tables/hash-tables/etc. 
  23823.  
  23824. On Oct 19,  8:46, Larry Wall wrote:
  23825. > In article <CF3Mwz.Hxr@bcstec.ca.boeing.com> ced@bcstec.ca.boeing.com (Charles Derykus) writes:
  23826. > : I think assoc.arrays deserve something whimsical. Maybe, along
  23827. > : the line of
  23828. > : 
  23829. > : joytable
  23830. > : happyhash
  23831. > : funarray   (say it fast)
  23832. > : ?
  23833. > : 
  23834. > : After all, Perl is getting awfully serious :-)
  23835. > I think that's the reason I lean towards "hash".  "map" is so...sober...
  23836. > Just try to say "hash" with a straight face.
  23837. > Larry
  23838. > -- End of excerpt from lwall@netlabs.com (Larry Wall)
  23839.  
  23840.  
  23841. For obvious reasons, I think the python documentation 
  23842. should be changed to call these objects "SPAM" ! 
  23843.  
  23844.  
  23845. - Steve Majewski 
  23846.  
  23847. [ P.S. Elvis was dead. But he is alive again. If anyone 
  23848.   has had bouncing mail to me, would you please resend
  23849.   it to sdm7g@Virginia.EDU. The domain addressing is 
  23850.   better - it can be redirected more easily. ] 
  23851.  
  23852. 
  23853. 
  23854. Replied: Mon, 25 Oct 1993 11:46:34 +0100
  23855. Replied: "Tim Peters <tim@ksr.com> "
  23856. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  23857.     id AA00702 (5.65b/3.11/CWI-Amsterdam); Fri, 22 Oct 1993 23:23:09 +0100
  23858. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  23859.     id AA12244; Fri, 22 Oct 1993 18:22:47 -0400
  23860. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  23861.     id AA08354; Fri, 22 Oct 93 18:23:43 EDT
  23862. Received: by kaos.ksr.com (4.1/KSR-2.0)
  23863.     id AA22366; Fri, 22 Oct 93 18:23:40 EDT
  23864. Message-Id: <9310222223.AA22366@kaos.ksr.com>
  23865. To: python-list@cwi.nl
  23866. Subject: Non-list ranges (was Re: obtaining the reversal of a sequence?)
  23867. Date: Fri, 22 Oct 93 18:23:39 -0400
  23868. From: Tim Peters <tim@ksr.com>
  23869.  
  23870. > >     for <ident> in range(<expression>):
  23871. >
  23872. > Well the compiler isn't very good at recognizing calls to built-in
  23873. > functions ('range' could be a local identifier with a different
  23874. > meaning).
  23875.  
  23876. Instead of the compiler, could the _runtime_ be made smart enough to
  23877. recognize that 'range' is being invoked in a context where a list isn't
  23878. truly needed?  Seems to me this use in 'for' is the only one worth
  23879. special-casing (I've never seen, e.g., someone write 'if i in range(n)',
  23880. or other non-for contexts where a list isn't needed).
  23881.  
  23882. > But someone else proposed that range() return a new object type that
  23883. > behaves like a sequence but doesn't store all its elements, just
  23884. > returns the one you ask for. ...
  23885.  
  23886. If this is the way to do it, I'd rather that range be left alone & a new
  23887. builtin introduced.  Think of all the Sieve of Eratosthenes programs
  23888. you'll break otherwise <wink>.
  23889.  
  23890. Or perhaps range could return an object of this new non-storing type, and
  23891. that also magically transforms itself into a vanilla list if used in a
  23892. context that requires a genuine list (including, but not limited to, the
  23893. "copy" context mentioned by Dirk).  In fact, I like this one best of all
  23894. -- users wouldn't need to know the non-storing type existed.  It's
  23895. an implementation hack, as it should be <grin>.
  23896.  
  23897. > An alternative solution, used in ABC, would be to have an efficient
  23898. > alternative representation of list objects consisting of ranges.
  23899.  
  23900. Agreed that's overkill; not common enough in Python (outside of "for") to
  23901. justify slowing down all lists.
  23902.  
  23903. voting-for-a-dirty-hack-under-the-covers-ly y'rs  - tim
  23904.  
  23905. Tim Peters   tim@ksr.com
  23906. not speaking for Kendall Square Research Corp
  23907. 
  23908. 
  23909. Replied: Mon, 25 Oct 1993 10:25:03 +0100
  23910. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list@cwi.nl"
  23911. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  23912.     id AA01825 (5.65b/3.11/CWI-Amsterdam); Sat, 23 Oct 1993 00:39:37 +0100
  23913. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11936>; Fri, 22 Oct 1993 16:39:14 PDT
  23914. Received: by holmes.parc.xerox.com id <16134>; Fri, 22 Oct 1993 16:39:08 -0700
  23915. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  23916.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  23917.           Fri, 22 Oct 1993 16:39:04 -0700 (PDT)
  23918. Message-Id: <ogm6wM4B0KGW82rNZq@holmes.parc.xerox.com>
  23919. Date:     Fri, 22 Oct 1993 16:39:04 PDT
  23920. Sender: Bill Janssen <janssen@parc.xerox.com>
  23921. From: Bill Janssen <janssen@parc.xerox.com>
  23922. To: python-list@cwi.nl
  23923. Subject: file.writelines()?
  23924.  
  23925. To write scripts, it would be handy to have something that lets one cat
  23926. a file to a file, something that's the equivalent of readlines(), but on
  23927. the output side (writelines()?), so that you could write
  23928.  
  23929.     out.writelines(in.readlines())
  23930.  
  23931. Bill
  23932. 
  23933. 
  23934. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  23935.     id AA28365 (5.65b/3.11/CWI-Amsterdam); Mon, 25 Oct 1993 10:25:05 +0100
  23936. Received: by voorn.cwi.nl with SMTP
  23937.     id AA03888 (5.65b/3.8/CWI-Amsterdam); Mon, 25 Oct 1993 10:25:04 +0100
  23938. Message-Id: <9310250925.AA03888=guido@voorn.cwi.nl>
  23939. To: Bill Janssen <janssen@parc.xerox.com>
  23940. Cc: python-list@cwi.nl
  23941. Subject: Re: file.writelines()? 
  23942. In-Reply-To: Your message of "Fri, 22 Oct 1993 16:39:04 MDT."
  23943.              <ogm6wM4B0KGW82rNZq@holmes.parc.xerox.com> 
  23944. From: Guido.van.Rossum@cwi.nl
  23945. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23946. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23947. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23948. Date: Mon, 25 Oct 1993 10:25:03 +0100
  23949. Sender: Guido.van.Rossum@cwi.nl
  23950.  
  23951. > To write scripts, it would be handy to have something that lets one cat
  23952. > a file to a file, something that's the equivalent of readlines(), but on
  23953. > the output side (writelines()?), so that you could write
  23954. >     out.writelines(in.readlines())
  23955.  
  23956. I just encountered the same need.  Consider it added to the next
  23957. release.  (Want a patch?  Mail me.)
  23958.  
  23959. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23960. 
  23961. 
  23962. To: Bill Janssen <janssen@parc.xerox.com>
  23963. cc: python-list@cwi.nl
  23964. Subject: Re: file.writelines()? 
  23965. In-reply-to: Your message of "Fri, 22 Oct 1993 16:39:04 MDT."
  23966.              <ogm6wM4B0KGW82rNZq@holmes.parc.xerox.com> 
  23967. From: Guido.van.Rossum@cwi.nl
  23968. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  23969. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  23970. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  23971. Date: Mon, 25 Oct 1993 10:25:03 +0100
  23972. Sender: guido
  23973.  
  23974. > To write scripts, it would be handy to have something that lets one cat
  23975. > a file to a file, something that's the equivalent of readlines(), but on
  23976. > the output side (writelines()?), so that you could write
  23977. >     out.writelines(in.readlines())
  23978.  
  23979. I just encountered the same need.  Consider it added to the next
  23980. release.  (Want a patch?  Mail me.)
  23981.  
  23982. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  23983. 
  23984. 
  23985. Replied: Mon, 25 Oct 1993 11:38:47 +0100
  23986. Replied: "gum@hal.com (John Gmuender) sijben@pegasus.esprit.ec.org"
  23987. Received: from HAL.COM by charon.cwi.nl with SMTP
  23988.     id AA29548 (5.65b/3.11/CWI-Amsterdam); Mon, 25 Oct 1993 11:32:09 +0100
  23989. Received: from gumworks.hal.com by hal.com (4.1/SMI-4.1.1)
  23990.     id AA11142; Mon, 25 Oct 93 03:32:05 PDT
  23991. Received: by gumworks.hal.com (4.1/SMI-4.1.2)
  23992.     id AA19142; Mon, 25 Oct 93 03:30:32 PDT
  23993. From: gum@hal.com (John Gmuender)
  23994. Message-Id: <9310251030.AA19142@gumworks.hal.com>
  23995. Subject: compiling stdwin port x11 on X11R5 ... and XLIB_ILLEGAL_ACCESS define ...
  23996. To: python-list@cwi.nl
  23997. Date: Mon, 25 Oct 93 3:30:31 PDT
  23998. Cc: massing@hal.com (Mike Massing)
  23999. X-Mailer: ELM [version 2.3 PL11]
  24000.  
  24001. Hi there:
  24002.  
  24003. I was just trying to add stdwin module to python and ran into 
  24004. this snag when compiling stdwin ...
  24005.  
  24006.     %  make
  24007.     cc -c    -I/tmp_mnt/sim/gumtools/src/python/stdwin/H          -g  /tmp_mnt/sim/gumtools/src/python/stdwin/Ports/x11/font.c
  24008.     "/tmp_mnt/sim/gumtools/src/python/stdwin/Ports/x11/font.c", line 117: gid undefined
  24009.  
  24010.  
  24011. which comes from this code snippet ....
  24012.  
  24013.     ...
  24014.         if (stdfont.name == NULL) {
  24015.                 stdfont.info= XQueryFont(_wd, DefaultGCOfScreen(_ws)->gid);
  24016.                 if (stdfont.info == NULL)
  24017.                         _wfatal("_winitfonts: no server default font");
  24018.                 stdfont.info->fid= 0;
  24019.         }
  24020.     ...
  24021.  
  24022.  
  24023. So, I started looking through everything and figured out that
  24024. X11R5 Xlib.h (as opposed to X11R4 Xlib.h), requires the define 
  24025.  
  24026.     XLIB_ILLEGAL_ACCESS
  24027.  
  24028. in order to reach into the GC and grab the gid.
  24029.  
  24030. I happily added this to the CFLAGS of the Makefile ...
  24031.  
  24032.     CFLAGS=         $(CPPFLAGS) $(OPTS) -DXLIB_ILLEGAL_ACCESS
  24033.  
  24034. and wholla ... it compiles!
  24035.  
  24036. Of course, this has probably been figured out fifty times before ...
  24037. I thought I would relate it anyway.
  24038.  
  24039. Now, on to adding stdwin to python :)
  24040. --__    ____ 
  24041.  /_//_// / /   
  24042. __/ gum@hal.com      
  24043. 
  24044. 
  24045. To: gum@hal.com (John Gmuender)
  24046. cc: sijben@pegasus.esprit.ec.org
  24047. cc: python-list@cwi.nl, massing@hal.com (Mike Massing)
  24048. Subject: Re: compiling stdwin port x11 on X11R5 ... and XLIB_ILLEGAL_ACCESS define ... 
  24049. In-reply-to: Your message of "Mon, 25 Oct 1993 03:30:31 MDT."
  24050.              <9310251030.AA19142@gumworks.hal.com> 
  24051. From: Guido.van.Rossum@cwi.nl
  24052. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24053. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24054. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24055. Date: Mon, 25 Oct 1993 11:38:47 +0100
  24056. Sender: guido
  24057.  
  24058. > So, I started looking through everything and figured out that
  24059. > X11R5 Xlib.h (as opposed to X11R4 Xlib.h), requires the define 
  24060. >     XLIB_ILLEGAL_ACCESS
  24061. > in order to reach into the GC and grab the gid.
  24062.  
  24063. Thanks for the bug report and the fix. I've heard of the bug once
  24064. before for a DEC alpha running OSF/1.  It appears not to be a problem
  24065. with the R5 Xlib.h straight from MIT that *I* am using.  Maybe it is
  24066. an OSF/1 problem?
  24067.  
  24068. Anyway, I imagine that eventually sdtwin should be fixed to use the
  24069. proper way of getting access to these variables (otherwise the define
  24070. wouldn't have that name would it?).
  24071.  
  24072. Paul Sijben, do you still have the fixes you applied to stdwin for
  24073. this?
  24074.  
  24075. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24076. 
  24077. 
  24078. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  24079.     id AA01155 (5.65b/3.11/CWI-Amsterdam); Mon, 25 Oct 1993 12:35:59 +0100
  24080. Received: by voorn.cwi.nl with SMTP
  24081.     id AA04771 (5.65b/3.8/CWI-Amsterdam); Mon, 25 Oct 1993 12:35:59 +0100
  24082. Message-Id: <9310251135.AA04771=guido@voorn.cwi.nl>
  24083. Subject: Re: Non-list ranges (was Re: obtaining the reversal of a sequence?) 
  24084. To: python-list@cwi.nl
  24085. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24086. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24087. Date: Mon, 25 Oct 1993 12:35:58 +0100
  24088. From: Guido van Rossum <Guido.van.Rossum@cwi.nl>
  24089.  
  24090. Tim Peters writes:
  24091.  
  24092. > Instead of the compiler, could the _runtime_ be made smart enough to
  24093. > recognize that 'range' is being invoked in a context where a list isn't
  24094. > truly needed?  Seems to me this use in 'for' is the only one worth
  24095. > special-casing (I've never seen, e.g., someone write 'if i in range(n)',
  24096. > or other non-for contexts where a list isn't needed).
  24097.  
  24098. Hmm, I suppose the compiler could recognize the range() call and
  24099. generate an instruction to set a hint flag that would be picked up by
  24100. the built-in range().  Will think about it some more...
  24101.  
  24102. > If this is the way to do it, I'd rather that range be left alone & a new
  24103. > builtin introduced.  Think of all the Sieve of Eratosthenes programs
  24104. > you'll break otherwise <wink>.
  24105.  
  24106. Really?  Actually the only non-for-loop use of range() I can imagine
  24107. is your "enumerated values" trick:
  24108.  
  24109.     [red, green, blue] = range(3)
  24110.  
  24111. > Or perhaps range could return an object of this new non-storing type, and
  24112. > that also magically transforms itself into a vanilla list if used in a
  24113. > context that requires a genuine list (including, but not limited to, the
  24114. > "copy" context mentioned by Dirk).  In fact, I like this one best of all
  24115. > -- users wouldn't need to know the non-storing type existed.  It's
  24116. > an implementation hack, as it should be <grin>.
  24117.  
  24118. Jack proposed this too.  It appears possible: when a
  24119. true-list-specific operation is called for, just update the
  24120. structure's contents and patch the type pointer, assuming a range
  24121. object takes no more space than a list object.  However we rejected it
  24122. because it would lead to a very obscure class of errors: there is code
  24123. around which compares an object's type with type([]) and this would
  24124. fail very mysteriously on range objects: for all practical purposes
  24125. they behave as lists, but not when their type is taken...
  24126.  
  24127. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24128.  
  24129. PS Tim: you got an earlier draft of this letter which accidentally
  24130. attributed the enum trick to Steve -- sorry about that!  The list
  24131. archives unambiguously show that you proposed it first :-)
  24132. 
  24133. 
  24134. Replied: Tue, 26 Oct 1993 10:45:38 +0100
  24135. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list"
  24136. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  24137.     id AA12218 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 01:35:53 +0100
  24138. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11717>; Mon, 25 Oct 1993 17:35:34 PDT
  24139. Received: by holmes.parc.xerox.com id <16134>; Mon, 25 Oct 1993 17:35:23 -0700
  24140. From: Bill Janssen <janssen@parc.xerox.com>
  24141. To: python-list@cwi.nl
  24142. Subject: strange thing about boolean expressions?
  24143. Message-Id: <93Oct25.173523pdt.16134@holmes.parc.xerox.com>
  24144. Date:     Mon, 25 Oct 1993 17:35:16 PDT
  24145.  
  24146. Why can't I use the following?
  24147.  
  24148.     v = None
  24149.     x = v or 'foo'
  24150.  
  24151. I get a syntax error.  Aren't boolean expressions valid on the
  24152. right hand side of an assignment?  I'd imagine that this evals
  24153. to 'foo'.
  24154.  
  24155. Bill
  24156. 
  24157. 
  24158. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  24159.     id AA12296 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 01:45:17 +0100
  24160. Received: from galen.med.virginia.edu by uvaarpa.virginia.edu id aa03858;
  24161.           25 Oct 93 20:45 EDT
  24162. Received: by galen.med.Virginia.EDU (5.67a8/1.34)
  24163.     id AA41898; Mon, 25 Oct 1993 20:44:41 -0400
  24164. Date: Mon, 25 Oct 1993 20:44:41 -0400
  24165. From: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  24166. Message-Id: <199310260044.AA41898@galen.med.Virginia.EDU>
  24167. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  24168. To: Bill Janssen <janssen@parc.xerox.com>
  24169. Subject: Re: strange thing about boolean expressions?
  24170. Cc: python-list@cwi.nl
  24171.  
  24172. On Oct 25, 17:35, Bill Janssen wrote:
  24173. > Why can't I use the following?
  24174. >     v = None
  24175. >     x = v or 'foo'
  24176. > I get a syntax error.  Aren't boolean expressions valid on the
  24177. > right hand side of an assignment?  I'd imagine that this evals
  24178. > to 'foo'.
  24179.  
  24180. x = ( v or 'foo' ) 
  24181.  
  24182. will work as expected.
  24183. The parends are necessary.
  24184. I think this is a relic in the parser of the early days when
  24185. boolean equal was "=" rather than "==" .
  24186.  
  24187. [ This came up in discussion earlier, but elvis.med.virginia.edu
  24188.  is again DEAD, and I can't get access to my python-list archive. ] 
  24189.  
  24190. - Steve Majewski 
  24191.  
  24192. 
  24193. 
  24194. Replied: Tue, 26 Oct 1993 14:47:52 +0100
  24195. Replied: "python-list@cwi.nl "
  24196. Replied: Tue, 26 Oct 1993 10:59:34 +0100
  24197. Replied: "Tim Peters <tim@ksr.com> python-list"
  24198. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  24199.     id AA13784 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 05:16:25 +0100
  24200. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  24201.     id AA26880; Tue, 26 Oct 1993 00:16:20 -0400
  24202. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  24203.     id AA07307; Tue, 26 Oct 93 00:16:16 EDT
  24204. Received: by kaos.ksr.com (4.1/KSR-2.0)
  24205.     id AA19635; Tue, 26 Oct 93 00:15:37 EDT
  24206. Message-Id: <9310260415.AA19635@kaos.ksr.com>
  24207. To: Guido.van.Rossum@cwi.nl
  24208. Subject: Re: Non-list ranges
  24209. Cc: python-list@cwi.nl
  24210. Date: Tue, 26 Oct 93 00:15:36 -0400
  24211. From: Tim Peters <tim@ksr.com>
  24212.  
  24213. > > [tim, whining that 'range' should be special-cased in 'for', by any
  24214. > >  dirty trick that works]
  24215. > > [how about at runtime via a context-sensitive trick?]
  24216. > [guido]
  24217. > Hmm, I suppose the compiler could recognize the range() call and
  24218. > generate an instruction to set a hint flag that would be picked up by
  24219. > the built-in range().  Will think about it some more...
  24220.  
  24221. If that's doable, I like it!  I don't understand the implementation well
  24222. enough to be helpful.  As a user, I whine that range makes perfect sense
  24223. the way it is already, and just needs to be trickier "somehow" in the one
  24224. context where its existing semantics are correct but overbearingly
  24225. inefficient.
  24226.  
  24227. > > If this is the way to do it, I'd rather that range be left alone & a new
  24228. > > builtin introduced.  Think of all the Sieve of Eratosthenes programs
  24229. > > you'll break otherwise <wink>.
  24230. >
  24231. > Really?  Actually the only non-for-loop use of range() I can imagine
  24232. > is your "enumerated values" trick:
  24233. >
  24234. >       [red, green, blue] = range(3)
  24235.  
  24236. Drat -- I was so relieved when you first attributed this kludgexxxxxx
  24237. fine technique to Majewski <wink>.  Here's a prime sieve program I pass
  24238. around here for pedagogical purposes; note that it uses "range" in 3
  24239. distinct ways, only one of which is clearly optimizable:
  24240.  
  24241. def siv( n ):  # return list of primes, in order, <= n
  24242.     if n <= 3:
  24243.         return range(2,n+1)
  24244.  
  24245.     if n & 1:
  24246.         n = n + 1
  24247.  
  24248.     primes = range(3,n,2)
  24249.     primes.insert(0,2)
  24250.  
  24251.     i = 1
  24252.     p = primes[i]
  24253.     sq = p*p
  24254.     while sq <= n:
  24255.         for x in range( sq, n, 2*p ):
  24256.             if x in primes:
  24257.                 primes.remove(x)
  24258.         i = i + 1
  24259.         p = primes[i]
  24260.         sq = p * p
  24261.  
  24262.     return primes
  24263.  
  24264. Of course there are quicker ways to write the venerable sieve in Python,
  24265. but this way is clean and people have found it instructive.  God only
  24266. knows how many have adopoted similar uses for range.
  24267.  
  24268. range-used-to-return-an-arithmetic-sequence-as-a-list is also useful for
  24269. the same reasons APL's iota function, and the Emac's calculator Calc's
  24270. function calc-index (both of which do much the same thing), are useful.
  24271. That's in support of a style of interactive computation that's not built
  24272. in to Python, but very easy to do in Python given a handful of helper
  24273. functions (like the 'map' and 'func' examples from a different thread).
  24274.  
  24275. You can also find non-'for' examples of 'range' in the library you
  24276. distribute <wink>:
  24277.  
  24278. auds.py:        list = range(RATE)
  24279. calendar.py:    r7 = range(7)
  24280. dis.py:opname = range(256)
  24281.  
  24282. Certainly the 'for' use is overwhelmingly most common, though.
  24283.  
  24284. > > Or perhaps range could return an object of this new non-storing type, and
  24285. > > that also magically transforms itself into a vanilla list if used in a
  24286. > > context that requires a genuine list ...
  24287. > [type() creates a problem]
  24288.  
  24289. I agree that's a problem, and will refrain from suggesting a kludge in
  24290. the type system too to worm around it.
  24291.  
  24292. My view is that range semantics are fine as-is, and speeding things up in
  24293. the 'for' context is simply a matter of translator optimization (& being
  24294. in the optimization biz myself, there is no limit to the sickness I'll
  24295. introduce behind the scenes to make a pleasant abstraction appear
  24296. healthy).
  24297.  
  24298. If you'd rather make range magical in a new & incompatible way, I can
  24299. live with that too.
  24300.  
  24301. Question:  In the absence of a
  24302.     from something import *
  24303.  
  24304. statement, are there other cases where Python cannot (in principle, & at
  24305. compile time) tell whether the name 'range' denotes the built-in?  This
  24306. is the tip of a much broader question, relevant a few years down the
  24307. road, when Python has taken over much of the world & I'll be thinking of
  24308. making a living by selling an optimizing Python compiler <smile>.
  24309.  
  24310. cleanliness-is-next-to-sterility-ly y'rs  - tim
  24311.  
  24312. Tim Peters   tim@ksr.com
  24313. not speaking for Kendall Square Research Corp
  24314. 
  24315. 
  24316. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  24317.     id AA17943 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 10:45:38 +0100
  24318. Received: by voorn.cwi.nl with SMTP
  24319.     id AA07746 (5.65b/3.8/CWI-Amsterdam); Tue, 26 Oct 1993 10:45:38 +0100
  24320. Message-Id: <9310260945.AA07746=guido@voorn.cwi.nl>
  24321. To: Bill Janssen <janssen@parc.xerox.com>
  24322. Cc: python-list@cwi.nl
  24323. Subject: Re: strange thing about boolean expressions? 
  24324. In-Reply-To: Your message of "Mon, 25 Oct 1993 17:35:16 MDT."
  24325.              <93Oct25.173523pdt.16134@holmes.parc.xerox.com> 
  24326. From: Guido.van.Rossum@cwi.nl
  24327. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24328. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24329. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24330. Date: Tue, 26 Oct 1993 10:45:38 +0100
  24331. Sender: Guido.van.Rossum@cwi.nl
  24332.  
  24333. > Why can't I use the following?
  24334. >     v = None
  24335. >     x = v or 'foo'
  24336. > I get a syntax error.  Aren't boolean expressions valid on the
  24337. > right hand side of an assignment?  I'd imagine that this evals
  24338. > to 'foo'.
  24339.  
  24340. Consider it fixed in 1.0.  It is a relic from the days when '=' was
  24341. also the equality comparison operator.  It also catches typos like
  24342.  
  24343.     x == 0            # intended: x = 0
  24344.  
  24345. which can be relly annoying to find, but I don't think the advantage
  24346. of catching those is worth the lack of orthogonality and surprise at
  24347. not being able to write "x = v or 'foo'".
  24348.  
  24349. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24350. 
  24351. 
  24352. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  24353.     id AA18185 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 10:59:36 +0100
  24354. Received: by voorn.cwi.nl with SMTP
  24355.     id AA07835 (5.65b/3.8/CWI-Amsterdam); Tue, 26 Oct 1993 10:59:36 +0100
  24356. Message-Id: <9310260959.AA07835=guido@voorn.cwi.nl>
  24357. To: Tim Peters <tim@ksr.com>
  24358. Cc: python-list@cwi.nl
  24359. Subject: Optimizing Python
  24360. In-Reply-To: Your message of "Tue, 26 Oct 1993 00:15:36 MET."
  24361.              <9310260415.AA19635@kaos.ksr.com> 
  24362. From: Guido.van.Rossum@cwi.nl
  24363. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24364. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24365. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24366. Date: Tue, 26 Oct 1993 10:59:35 +0100
  24367. Sender: Guido.van.Rossum@cwi.nl
  24368.  
  24369. Tim Peters brings up another interesting
  24370.  
  24371. > Question:  In the absence of a
  24372. >     from something import *
  24373. > statement, are there other cases where Python cannot (in principle, & at
  24374. > compile time) tell whether the name 'range' denotes the built-in?  This
  24375. > is the tip of a much broader question, relevant a few years down the
  24376. > road, when Python has taken over much of the world & I'll be thinking of
  24377. > making a living by selling an optimizing Python compiler <smile>.
  24378.  
  24379. Actually, since built-in names come after module-global names, it is
  24380. always possible to sabotage a module by doing something like
  24381.  
  24382.     def sick_range(n):
  24383.         return range(1, n+1)
  24384.  
  24385.     import foobar
  24386.     foobar.range = sick_range
  24387.  
  24388.     print foobar.innocent_function()
  24389.  
  24390. Depending upon the use that foobar.innocent_function() makes of
  24391. range() this could have no effect, a benign effect, a humorous effect,
  24392. or a disastrous effect...
  24393.  
  24394. A global scan of all modules might prove that there is no redefinition
  24395. of 'range' anywhere, but a single use of exec or even setattr may make
  24396. everything uncertain again...
  24397.  
  24398. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24399. 
  24400. 
  24401. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  24402.     id AA24064 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 14:47:53 +0100
  24403. Received: by voorn.cwi.nl with SMTP
  24404.     id AA09118 (5.65b/3.8/CWI-Amsterdam); Tue, 26 Oct 1993 14:47:53 +0100
  24405. Message-Id: <9310261347.AA09118=guido@voorn.cwi.nl>
  24406. To: python-list@cwi.nl
  24407. Subject: Non-list ranges -- is it worth it?
  24408. From: Guido.van.Rossum@cwi.nl
  24409. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24410. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24411. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24412. Date: Tue, 26 Oct 1993 14:47:52 +0100
  24413. Sender: Guido.van.Rossum@cwi.nl
  24414.  
  24415. I just did a reality check.
  24416.  
  24417. Someone from XVT donated a range object implementation (thanks!) and I
  24418. put it in under a different name ("xrange").  Results: a for loop with
  24419. an empty body ("pass") over range(100000), which actually creates a
  24420. list and 100,000 integer objects, takes about 3.13 seconds on my
  24421. machine (fastest of 3 runs) while the same loop using xrange(100000)
  24422. takes 3.07 (best of 3 in both cases).  That is a speed-up of less
  24423. than 2 percent!
  24424.  
  24425. This was on an SGI Indigo with a 50 MHZ MIPS R4000 CPU.
  24426.  
  24427. On a Sun ELC, the results are even weirder: the loop using xrange()
  24428. takes 17.5 secs, while using range() it takes only 12.8 seconds!!!
  24429.  
  24430. A possible explanation for this unexpectged behavior might be
  24431. instruction cache size on the Sparc chip: creating 100,000 integer
  24432. objects in a tight loop (as range() does) may execute entirely out of
  24433. the cache and thus be much faster than creating one object on each
  24434. iteration through the for loop, where many other lines of C code are
  24435. hit in between...
  24436.  
  24437. Note that even though this creates 100,000 integer objects, it does
  24438. not make 100,000 calls to malloc() -- the allocation of integers is
  24439. already optimized (to save 25% on space).  The measurements were
  24440. actually done using a version of the interpreter with some other
  24441. optimizations (such as keeping a cache of small integers) but this
  24442. shouldn't affect the measurements much.
  24443.  
  24444. My personal conclusion: it's not worth optimizing range() at all...
  24445.  
  24446. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24447.  
  24448. "Meten is weten"
  24449. 
  24450. 
  24451. To: python-list@cwi.nl
  24452. Subject: Non-list ranges -- is it worth it?
  24453. From: Guido.van.Rossum@cwi.nl
  24454. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24455. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24456. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24457. Date: Tue, 26 Oct 1993 14:47:52 +0100
  24458. Sender: guido
  24459.  
  24460. I just did a reality check.
  24461.  
  24462. Someone from XVT donated a range object implementation (thanks!) and I
  24463. put it in under a different name ("xrange").  Results: a for loop with
  24464. an empty body ("pass") over range(100000), which actually creates a
  24465. list and 100,000 integer objects, takes about 3.13 seconds on my
  24466. machine (fastest of 3 runs) while the same loop using xrange(100000)
  24467. takes 3.07 (best of 3 in both cases).  That is a speed-up of less
  24468. than 2 percent!
  24469.  
  24470. This was on an SGI Indigo with a 50 MHZ MIPS R4000 CPU.
  24471.  
  24472. On a Sun ELC, the results are even weirder: the loop using xrange()
  24473. takes 17.5 secs, while using range() it takes only 12.8 seconds!!!
  24474.  
  24475. A possible explanation for this unexpectged behavior might be
  24476. instruction cache size on the Sparc chip: creating 100,000 integer
  24477. objects in a tight loop (as range() does) may execute entirely out of
  24478. the cache and thus be much faster than creating one object on each
  24479. iteration through the for loop, where many other lines of C code are
  24480. hit in between...
  24481.  
  24482. Note that even though this creates 100,000 integer objects, it does
  24483. not make 100,000 calls to malloc() -- the allocation of integers is
  24484. already optimized (to save 25% on space).  The measurements were
  24485. actually done using a version of the interpreter with some other
  24486. optimizations (such as keeping a cache of small integers) but this
  24487. shouldn't affect the measurements much.
  24488.  
  24489. My personal conclusion: it's not worth optimizing range() at all...
  24490.  
  24491. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24492.  
  24493. "Meten is weten"
  24494. 
  24495. 
  24496. Replied: Tue, 26 Oct 1993 16:16:06 +0100
  24497. Replied: "Kevan Heydon <kevan@Harston.CV.COM> python-list@cwi.nl"
  24498. Received: from MEDUSA.CV.COM by charon.cwi.nl with SMTP
  24499.     id AA24295 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 15:04:14 +0100
  24500. Received: from Harston.CV.COM by medusa.CV.COM (8.6.3/8.5/Medusa)
  24501.     id OAA12676; Tue, 26 Oct 1993 14:04:01 GMT
  24502. Received: from alrami.Harston.CV.COM by Harston.CV.COM (4.1/SMI-4.1.1/Harston)
  24503.     id AA01229; Tue, 26 Oct 93 14:03:51 GMT
  24504. Date: Tue, 26 Oct 93 14:03:51 GMT
  24505. From: Kevan Heydon <kevan@Harston.CV.COM>
  24506. Message-Id: <9310261403.AA01229@Harston.CV.COM>
  24507. To: python-list@cwi.nl
  24508. Subject: Re: Non-list ranges
  24509.  
  24510.  
  24511. Hello,
  24512.  
  24513. I have been follwing the thread on Non-list ranges with some interest and would
  24514. like to mention, as a little diversion, how our in house language (Bacis2) does it.
  24515. Bacis has the concept of iterator functions that "yield" values to a loop.
  24516. Hence you define an iterator function such:
  24517.  
  24518.     my_range :- iter(min,max,step)
  24519.         value :- min
  24520.         loop
  24521.             if value > max then
  24522.                 break
  24523.             endif
  24524.             yield value
  24525.             value :- value + step
  24526.         endloop
  24527.     enditer
  24528.  
  24529. with a calling loop such as:
  24530.  
  24531.     loop for var over my_range(1,20,2)
  24532.         sys_show(var)
  24533.     endloop
  24534.  
  24535. gives:
  24536.     1
  24537.     3
  24538.     5
  24539.     .
  24540.     .
  24541.     19
  24542.  
  24543. The statement "yield value" suspends the execution of the iterator and passes
  24544. "value" to the loop that called it. The next time round the calling loop when the
  24545. iterator is called again the suspended execution resumes after the yield statement.
  24546. Obviously the calling loop terminates when the iter function terminates. 
  24547.  
  24548. While this type of functionality can be achieved by writing a function to return
  24549. a list, an iterator function does it without allocating space for a, potentialy
  24550. very long, list.
  24551.  
  24552. Could something like this be done in Python?
  24553.  
  24554. Kevan Heydon
  24555.  
  24556. Computervision R&D Ltd, Harston, England
  24557. 
  24558. 
  24559. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  24560.     id AA25604 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 16:16:08 +0100
  24561. Received: by voorn.cwi.nl with SMTP
  24562.     id AA09431 (5.65b/3.8/CWI-Amsterdam); Tue, 26 Oct 1993 16:16:07 +0100
  24563. Message-Id: <9310261516.AA09431=guido@voorn.cwi.nl>
  24564. To: Kevan Heydon <kevan@Harston.CV.COM>
  24565. Cc: python-list@cwi.nl
  24566. Subject: Re: Non-list ranges 
  24567. In-Reply-To: Your message of "Tue, 26 Oct 1993 14:03:51 MET."
  24568.              <9310261403.AA01229@Harston.CV.COM> 
  24569. From: Guido.van.Rossum@cwi.nl
  24570. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24571. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24572. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24573. Date: Tue, 26 Oct 1993 16:16:07 +0100
  24574. Sender: Guido.van.Rossum@cwi.nl
  24575.  
  24576. > I have been follwing the thread on Non-list ranges with some
  24577. > interest and would like to mention, as a little diversion, how our
  24578. > in house language (Bacis2) does it.
  24579. > Bacis has the concept of iterator functions that "yield" values to a loop.
  24580. [...explanation deleted...]
  24581. > While this type of functionality can be achieved by writing a
  24582. > function to return a list, an iterator function does it without
  24583. > allocating space for a, potentialy very long, list.
  24584. > Could something like this be done in Python?
  24585.  
  24586. Interesting point!  You can more or less do this with a class.  Here
  24587. is a simple example; it yields the first n elements of the Fibonacci
  24588. sequence (1, 1, 2, 3, 5, 8, 13, ...):
  24589.  
  24590. class Fib:
  24591.  
  24592.     # constructor -- argument is length of sequence
  24593.     def __init__(self, n):
  24594.         self.size = n
  24595.         self.reset()
  24596.  
  24597.     def reset(self):
  24598.         self.last_index = 0
  24599.         self.a = self.b = 1
  24600.  
  24601.     # return len(self)
  24602.     def __len__(self):
  24603.         return self.size
  24604.  
  24605.     # return self[i]
  24606.     def __getitem__(self, i):
  24607.         if i < self.last_index:
  24608.             self.reset()
  24609.         while i > self.last_index:
  24610.             self.last_index = self.last_index + 1
  24611.             self.a, self.b = self.b, self.a + self.b
  24612.         return self.a
  24613.  
  24614. This example tries to behave like a real sequence -- only it is faster
  24615. when you ask for the items in their natural sequence, hence the
  24616. reset() method.  For iterators that will *only* be used in a for loop,
  24617. __getitem__ could raise an expression when an item is asked for out of
  24618. sequence.
  24619.  
  24620. The catch is that you need to know how many values a particular
  24621. iterator instance will yield, so you can't use it to simulate an
  24622. infinite or indefinite sequence.
  24623.  
  24624. If iterators become popular in Python, it might be possible to
  24625. redefine the 'for' semantics and extend the interface to sequences to
  24626. allow for loops over (pseudo-)sequences of indefinite length.  But I
  24627. don't know how much use there is for this, since it is generally just
  24628. as easy to use a while loop for a loop over an indefinite sequence...
  24629.  
  24630. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24631. 
  24632. 
  24633. To: Kevan Heydon <kevan@Harston.CV.COM>
  24634. cc: python-list@cwi.nl
  24635. Subject: Re: Non-list ranges 
  24636. In-reply-to: Your message of "Tue, 26 Oct 1993 14:03:51 MET."
  24637.              <9310261403.AA01229@Harston.CV.COM> 
  24638. From: Guido.van.Rossum@cwi.nl
  24639. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  24640. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  24641. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  24642. Date: Tue, 26 Oct 1993 16:16:07 +0100
  24643. Sender: guido
  24644.  
  24645. > I have been follwing the thread on Non-list ranges with some
  24646. > interest and would like to mention, as a little diversion, how our
  24647. > in house language (Bacis2) does it.
  24648. > Bacis has the concept of iterator functions that "yield" values to a loop.
  24649. [...explanation deleted...]
  24650. > While this type of functionality can be achieved by writing a
  24651. > function to return a list, an iterator function does it without
  24652. > allocating space for a, potentialy very long, list.
  24653. > Could something like this be done in Python?
  24654.  
  24655. Interesting point!  You can more or less do this with a class.  Here
  24656. is a simple example; it yields the first n elements of the Fibonacci
  24657. sequence (1, 1, 2, 3, 5, 8, 13, ...):
  24658.  
  24659. class Fib:
  24660.  
  24661.     # constructor -- argument is length of sequence
  24662.     def __init__(self, n):
  24663.         self.size = n
  24664.         self.reset()
  24665.  
  24666.     def reset(self):
  24667.         self.last_index = 0
  24668.         self.a = self.b = 1
  24669.  
  24670.     # return len(self)
  24671.     def __len__(self):
  24672.         return self.size
  24673.  
  24674.     # return self[i]
  24675.     def __getitem__(self, i):
  24676.         if i < self.last_index:
  24677.             self.reset()
  24678.         while i > self.last_index:
  24679.             self.last_index = self.last_index + 1
  24680.             self.a, self.b = self.b, self.a + self.b
  24681.         return self.a
  24682.  
  24683. This example tries to behave like a real sequence -- only it is faster
  24684. when you ask for the items in their natural sequence, hence the
  24685. reset() method.  For iterators that will *only* be used in a for loop,
  24686. __getitem__ could raise an expression when an item is asked for out of
  24687. sequence.
  24688.  
  24689. The catch is that you need to know how many values a particular
  24690. iterator instance will yield, so you can't use it to simulate an
  24691. infinite or indefinite sequence.
  24692.  
  24693. If iterators become popular in Python, it might be possible to
  24694. redefine the 'for' semantics and extend the interface to sequences to
  24695. allow for loops over (pseudo-)sequences of indefinite length.  But I
  24696. don't know how much use there is for this, since it is generally just
  24697. as easy to use a while loop for a loop over an indefinite sequence...
  24698.  
  24699. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  24700. 
  24701. 
  24702. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  24703.     id AA28363 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 18:50:04 +0100
  24704. Received: from galen.med.virginia.edu by uvaarpa.virginia.edu id aa26439;
  24705.           26 Oct 93 13:49 EDT
  24706. Received: by galen.med.Virginia.EDU (5.67a8/1.34)
  24707.     id AA39914; Tue, 26 Oct 1993 13:49:49 -0400
  24708. Date: Tue, 26 Oct 1993 13:49:49 -0400
  24709. From: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  24710. Message-Id: <199310261749.AA39914@galen.med.Virginia.EDU>
  24711. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  24712. To: python-list@cwi.nl
  24713. Subject: For and Non-lists 
  24714.  
  24715.  
  24716. On Oct 26, 16:16, Guido.van.Rossum@cwi.nl wrote:
  24717. >
  24718. > > Could something like this be done in Python?
  24719. > Interesting point!  You can more or less do this with a class. 
  24720.  
  24721. Having tried this sort of thing out before, I'll note that both
  24722. 'for' and 'in' will work on pseudo-sequence or sequence-like
  24723. objects that provide __len__(), and __getitem__( index ) methods.
  24724.  
  24725. > The catch is that you need to know how many values a particular
  24726. > iterator instance will yield, so you can't use it to simulate an
  24727. > infinite or indefinite sequence.
  24728.  
  24729. One kludge is just to make 'len()' *LIE*. Return a value that is 
  24730. larger than any realistic value. This implies that your 'for'
  24731. will break on an appropriate value. ( And you need  to raise
  24732. an exception to break out of an 'in' that is false! )
  24733.  
  24734. Also: 'for' appears to call len() method before each call to 
  24735. getitem() method. So you only really have to lie a little bit - 
  24736. only promise one more item. And if you're going to promise 
  24737. one more, you might as well look ahead and cache the next item -
  24738. then you can *eventually* tell the truth. 
  24739.  
  24740. However, these extra len() calls would seem to be an obvious
  24741. part of the 'for' to optomize out - so maybe we can't rely on
  24742. that method continuing to work.(?)  Or is that len() a necessary
  24743. part of the expected semantics of 'for' over an object? ( This 
  24744. also makes it clear why you should use the suggested 'for x in s[:]' 
  24745. when the body is going to modify 's'. ) 
  24746.  
  24747. > If iterators become popular in Python, it might be possible to
  24748. > redefine the 'for' semantics and extend the interface to sequences to
  24749. > allow for loops over (pseudo-)sequences of indefinite length.  But I
  24750. > don't know how much use there is for this, since it is generally just
  24751. > as easy to use a while loop for a loop over an indefinite sequence...
  24752.  
  24753.  
  24754. How about len() ==> None as a sign of an indefinite length sequence.
  24755. len() of a non-sequence raises an exception, so the meaning is not
  24756. overloaded. [ except that: ( None < 0 ), so the test is awkward. ]
  24757.  
  24758.  
  24759. I find iterators and sequences quite a natural way of dealing with a
  24760. number of problems. My *other* favorite language, Icon, has
  24761. co-expressions and co-routines ( the latter much like the basic2
  24762. example ) and an 'every' to force full evaluation. I think the object
  24763. system (IDOL) built on top of Icon uses coexpressions to make objects.
  24764. ( Tim may be more knowledgable on this - I've never used Idol ) In
  24765. python, it's the other way around - objects are the primary means of
  24766. preserving state. I only wish it was a bit easier to create "quick"
  24767. co-expression like objects. The problem is that there's no easy way to
  24768. pass THUNKS or unevaluated expressions around in python except as
  24769. strings to eval/exec. But even if it's not as easy as I'ld like, it's
  24770. do-able. 
  24771.  
  24772.  
  24773. The other reason I tend to use 'for' over a sequence, has to do
  24774. with some issues of style I have raised before. Since Python has
  24775. no C-like assign and test, and I don't like to special case the
  24776. first assignment at the top of the loop,  and even "while 'true' :
  24777.  ... if some_test() : break " , while I think it looks "cleaner",
  24778. tends to hide the logic of the loop - so if I can at all coerce
  24779. the logic into "for x in sequence: process(x)", I tend to do so.
  24780.  
  24781.  
  24782. So if I could think of a good proposal to make 'for' more
  24783. "object-oriented" ( i.e. behave differently for different 
  24784. objects ), I'ld tend to be in favor of it.  But I agree
  24785. that additional feature's aren't *necessary*, so I don't 
  24786. think they are worth considering unless they can fit in 
  24787. without much trouble. 
  24788.  
  24789.  
  24790. How about something like: 
  24791.   for y in every f(x) :
  24792. meaning to continue to apply f(x) for a new value y. 
  24793. The question is, what is the implied loop exit? 
  24794.   y == None 
  24795. or 
  24796.   y in ( None, 0, '', [], (,) ) # i.e. any 'false' value 
  24797. or 
  24798.  no implied exit, must terminate by a raised signal in 
  24799.  f(x) or a explicit test/break in the body of the for.
  24800.  [ Could there be a special "loop break" exception ,
  24801.   which is caught and invisibly handled in loops ? ] 
  24802.  
  24803.  
  24804. [Note: Icon handles this by having a special value for failure. ]
  24805.  
  24806.  
  24807. - Steve Majewski 
  24808.  
  24809.  
  24810. 
  24811. 
  24812. Received: from ogre.cica.indiana.edu by charon.cwi.nl with SMTP
  24813.     id AA29291 (5.65b/3.11/CWI-Amsterdam); Tue, 26 Oct 1993 20:17:09 +0100
  24814. Message-Id: <9310261917.AA29291=emo@ogre.cica.indiana.edu@charon.cwi.nl>
  24815. Received: by ogre.cica.indiana.edu
  24816.     id AA18472; Tue, 26 Oct 1993 14:17:03 -0500
  24817. Date: Tue, 26 Oct 1993 14:17:03 -0500
  24818. From: Eric Ost <emo@ogre.cica.indiana.edu>
  24819. To: guido@cwi.nl
  24820. Subject: python mailing list
  24821.  
  24822. Greetings Guido,
  24823.  
  24824. Our mail server went down recently with disk problems and incoming
  24825. mail was bouncing all over the place.  The system should be back 
  24826. to normal now.  Sorry for cluttering your mailbox with the returned msgs.
  24827.  
  24828. Python's great!
  24829.  
  24830. eric
  24831. 
  24832. 
  24833. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  24834.     id AA05836 (5.65b/3.11/CWI-Amsterdam); Wed, 27 Oct 1993 07:05:59 +0100
  24835. Received: from galen.med.virginia.edu by uvaarpa.virginia.edu id aa01318;
  24836.           27 Oct 93 2:05 EDT
  24837. Received: by galen.med.Virginia.EDU (5.67a8/1.34)
  24838.     id AA37093; Wed, 27 Oct 1993 01:39:57 -0400
  24839. Date: Wed, 27 Oct 1993 01:39:57 -0400
  24840. From: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  24841. Message-Id: <199310270539.AA37093@galen.med.Virginia.EDU>
  24842. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  24843. To: python-list@cwi.nl
  24844. Subject: A sequence class that lies about it length
  24845.  
  24846.  
  24847. Well, while I'm sitting here waiting for restore tapes to 
  24848. finish spinning, I didn't have anything better I could do,
  24849. so I wrote a test of a sequence class that lies about it's 
  24850. length. Not at all debugged or optimized. 
  24851.  
  24852. The last 5 lines at the end will test it by printing the 
  24853. nominal (sometimes untrue) length, the current length of
  24854. the internal buffer, and (via pipe to unix 'nl' ) the
  24855. line numbered lines of 'flines.py' 
  24856.  
  24857. - Steve Majewski <sdm7g@Virginia.EDU>
  24858.  
  24859. #--------------
  24860. # Class Flines
  24861. #
  24862. # This is a demonstration/test of a class that "lazily" coerces 
  24863. # the lines of a file into a sequence. 
  24864. # It was written mostly to test the technique of lying about
  24865. # the length of the sequence by +1, except at the end.
  24866. # It has the feature that it will continue to try to read
  24867. # file when it gets to eof, so even if file continues to grow,
  24868. # so that:
  24869. #  for x in flines_obj: print x[:-1]
  24870. # will always print whatever is currently available.
  24871. # So it's actually good for something. 
  24872. # ( But that also means that flines_obj[-1] is very context sensitive! )
  24873. #
  24874. # <sdm7g@Virginia.EDU>
  24875. #
  24876. import posix
  24877. import builtin
  24878.  
  24879. def rdopen( fname ):    # open file or pipe for reading
  24880.     if fname[-1] == '|' :
  24881.         open = posix.popen
  24882.         fname = fname[:-1]
  24883.     else: open = builtin.open
  24884.     return open( fname, 'r' )
  24885.  
  24886. class Flines:
  24887.     def _lie( self ): return self._len + 1
  24888.     def _get1( self ):
  24889.         if self._cache[-1]:
  24890.             self._cache.append( self._file.readline() ) 
  24891.             self._len = self._len + 1
  24892.         else: 
  24893.             self._cache[-1] = self._file.readline() 
  24894.     def __init__( self, fname ):
  24895.         self._file = rdopen( fname )
  24896.         self._cache = [ self._file.readline() ] 
  24897.         self._len = 1
  24898.     def __len__( self ):
  24899.         if self._cache[-1]:
  24900.             return self._lie() 
  24901.         else:
  24902.             self._get1()
  24903.             if self._cache[-1]: return self._lie()
  24904.             else: return self._len 
  24905.     def __getitem__( self, j ):
  24906.         if j < 0 :
  24907.            self._get1()
  24908.         elif j >= self._len :
  24909.            for index in range( self._len, j+1 ): self._get1()
  24910.         return self._cache[j]
  24911.     def __del__(self):
  24912.         self._file.close()
  24913.     def __getslice__( self, i, j ):
  24914.         return self._cache[i:j]
  24915.  
  24916. F=Flines('nl -ba flines.py|' )
  24917. print '# Test me once...'
  24918. for x in F : print len(F),F._len, x[:-1]
  24919. print '# Test me twice ... ' 
  24920. for x in F : print len(F),F._len, x[:-1]
  24921.  
  24922. 
  24923. 
  24924. Received: from meerman.cwi.nl by charon.cwi.nl with SMTP
  24925.     id AA19439 (5.65b/3.11/CWI-Amsterdam); Wed, 27 Oct 1993 21:10:16 +0100
  24926. Received: from hopscotch.ksr.com by meermin.cwi.nl with SMTP
  24927.     id AA26001 (5.65b/3.9/CWI-Amsterdam); Wed, 27 Oct 1993 21:10:13 +0100
  24928. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  24929.     id AA14820; Wed, 27 Oct 1993 16:08:39 -0400
  24930. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  24931.     id AA10270; Wed, 27 Oct 93 16:08:38 EDT
  24932. Received: by kaos.ksr.com (4.1/KSR-2.0)
  24933.     id AA28740; Wed, 27 Oct 93 16:07:45 EDT
  24934. Message-Id: <9310272007.AA28740@kaos.ksr.com>
  24935. To: Guido.van.Rossum@cwi.nl
  24936. Subject: Re: Optimizing Python
  24937. Cc: python-list@cwi.nl
  24938. Date: Wed, 27 Oct 93 16:07:44 -0400
  24939. From: Tim Peters <tim@ksr.com>
  24940.  
  24941. > > [tim]
  24942. > > In the absence of a
  24943. > >     from something import *
  24944. > > statement, are there other cases where Python cannot (in principle, & at
  24945. > > compile time) tell whether the name 'range' denotes the built-in? ...
  24946.  
  24947. > [guido]
  24948. > Actually, since built-in names come after module-global names, it is
  24949. > always possible to sabotage a module by doing something like [importing
  24950. > the module and fiddling its namespace directly; or via exec or setattr]
  24951.  
  24952. That's OK; it's possible to worm around that in a compiler, and some of
  24953. the ways of doing so are even safe <wink>.  A first cut would probably
  24954. like to assume that built-in names denote built-in objects in the absence
  24955. of a contradictory switch/pragma etc, and that would get 95% of the gain
  24956. for 5% of the work (in return for being unsafe).
  24957.  
  24958. would-be-an-interesting-albeit-involved-project-ly y'rs  - tim
  24959.  
  24960. Tim Peters   tim@ksr.com
  24961. not speaking for Kendall Square Research Corp
  24962. 
  24963. 
  24964. Received: from hopscotch.ksr.com by charon.cwi.nl with SMTP
  24965.     id AA21228 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 00:05:09 +0100
  24966. Received: from ksr.com (frankenstein.ksr.com) by hopscotch.ksr.com with SMTP
  24967.     id AA16475; Wed, 27 Oct 1993 19:04:48 -0400
  24968. Received: from kaos.ksr.com by ksr.com (4.0/SMI-3.2)
  24969.     id AA12323; Wed, 27 Oct 93 19:04:51 EDT
  24970. Received: by kaos.ksr.com (4.1/KSR-2.0)
  24971.     id AA08202; Wed, 27 Oct 93 19:04:46 EDT
  24972. Message-Id: <9310272304.AA08202@kaos.ksr.com>
  24973. To: python-list@cwi.nl
  24974. Subject: Re: Non-list ranges; iterators in general
  24975. Date: Wed, 27 Oct 93 19:04:45 -0400
  24976. From: Tim Peters <tim@ksr.com>
  24977.  
  24978. > [guido times a range object implementation with discouraging results]
  24979. > ...
  24980. > My personal conclusion: it's not worth optimizing range() at all...
  24981.  
  24982. No argument here -- & very interesting.
  24983.  
  24984. > [discussion of iterators]
  24985.  
  24986. > [steve]
  24987. > ...
  24988. > [Note: Icon handles this [breaking out of an iterator loop] by having a
  24989. > special value for failure. ]
  24990.  
  24991. Well, it's kinda _implemented_ that way, but the user doesn't (need to)
  24992. know anything about that.  _Every_ expression in Icon generates a
  24993. sequence of 0 or more results, and to say that an Icon expression "fails"
  24994. is the same as saying the expression has an empty (length 0) result
  24995. sequence.
  24996.  
  24997. The point is that iterators fit naturally into such a scheme, since
  24998. they're just one more expression that yields 0 or more results.  It's
  24999. hard to see how to support this in a general way without buying into the
  25000. whole co-routine business, and that seems like a lot of new machinery for
  25001. Python.
  25002.  
  25003. People might be interested in seeing how this works in Icon.  So here's
  25004. an Icon version of the Fibonacci example.  Abstractly, it looks much like
  25005. Basic2's approach:
  25006.  
  25007. procedure main()
  25008.    every x := fib() do
  25009.       if x < 500 then write( x )
  25010.       else break
  25011. end
  25012.  
  25013. procedure fib()
  25014.    local a, b, sum
  25015.    a := b := 1   # vanilla multiple assignment
  25016.    repeat {      # infinite loop
  25017.       suspend a  # 'suspend' sez to return the value, & also allow resuming
  25018.       sum := a + b
  25019.       a   := b
  25020.       b   := sum
  25021.    }
  25022. end
  25023.  
  25024. That prints
  25025.  
  25026. 1
  25027. 1
  25028. 2
  25029. 3
  25030. 5
  25031. 8
  25032. 13
  25033. 21
  25034. 34
  25035. 55
  25036. 89
  25037. 144
  25038. 233
  25039. 377
  25040.  
  25041. The successive generation of fib's values is driven by the "every"
  25042. control structure.  A kind of closure can also be created by the "create"
  25043. construct, and resumed as desired with the invocation operator "@"; e.g.,
  25044.  
  25045. procedure main()
  25046.    thunk := create fib()
  25047.    write( @thunk )
  25048.    write( @thunk )
  25049.    write( @thunk )
  25050.    write( @thunk )
  25051. end
  25052.  
  25053. prints
  25054.  
  25055. 1
  25056. 1
  25057. 2
  25058. 3
  25059.  
  25060. More general mechanisms exist for passing control in arbitary co-routine
  25061. fashion, etc.
  25062.  
  25063. This is all very slick in theory, but in my experience Icon's
  25064. implementation of these features is burdensome & buggy.  Icon was
  25065. designed for exploring new language ideas, so that's fine for Icon.  I
  25066. don't think it fits Python's worldview, though.
  25067.  
  25068. > [ Could there be a special "loop break" exception ,
  25069. >  which is caught and invisibly handled in loops ? ]
  25070.  
  25071. That seems the cleanest way to get the most useful part of the
  25072. functionality in Python, but I worry more about how much hair it would
  25073. add to permit suspending & resuming the "sequence" part of "for thing in
  25074. sequence:".
  25075.  
  25076. > [steve]
  25077. > ...
  25078. > So if I could think of a good proposal to make 'for' more "object-
  25079. > oriented" ( i.e. behave differently for different objects ), I'ld tend
  25080. > to be in favor of it.  But I agree that additional feature's aren't
  25081. > *necessary*, so I don't think they are worth considering unless they
  25082. > can fit in without much trouble.
  25083.  
  25084. Agreed on all counts.
  25085.  
  25086. harmoniously y'rs  - tim
  25087.  
  25088. Tim Peters   tim@ksr.com
  25089. not speaking for Kendall Square Research Corp
  25090. 
  25091. 
  25092. Received: from pl122e.eecs.lehigh.edu by charon.cwi.nl with SMTP
  25093.     id AA23087 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 03:17:53 +0100
  25094. Received: by PL122e.EECS.Lehigh.EDU (5.61/1.34)
  25095.     id AA11088; Wed, 27 Oct 93 22:04:49 -0400
  25096. Date: Wed, 27 Oct 93 22:04:49 -0400
  25097. From: tb06@PL122e.EECS.Lehigh.EDU (TERRENCE BRANNON)
  25098. Message-Id: <9310280204.AA11088@PL122e.EECS.Lehigh.EDU>
  25099. To: python-list@cwi.nl
  25100. Subject: final pre-Usenet posting of "Survey of Interp. Lang."
  25101.  
  25102.  
  25103. This is the final posting of this paper before it goes to Usenet. Please email
  25104. me any input you have:
  25105.  
  25106. \documentstyle{report}
  25107. \pagestyle{headings}
  25108.  
  25109. \begin{document}
  25110.  
  25111. \title {
  25112.    Survey of Quick Interpreted Languages
  25113. }
  25114.  
  25115. \author {
  25116.    Terrence Monroe Brannon \\ 
  25117.    PO Box 5027 \\ 
  25118.    Bethlehem, PA 18015 \\
  25119.    $tb06@pl122e.eecs.lehigh.edu$
  25120. }     
  25121.  
  25122. \maketitle
  25123.  
  25124. \tableofcontents
  25125.  
  25126.  
  25127.  
  25128. \part {Introduction and Conclusion}
  25129.  
  25130.  
  25131. The purpose of this report is to expose people to several languages which
  25132. can cutdown/eliminate shell programming and C programming.
  25133.  
  25134.  
  25135.  
  25136. All of these languages are quick interpreted languages which can do
  25137. things in a few lines which might take hundreds of lines of C/shell
  25138. code. They typically have all of the following features:
  25139.  
  25140. \begin {itemize}
  25141.  
  25142. \item The ability to modify the source code at runtime, adding new
  25143. procedures or modifying old ones.
  25144. \item An efficiently hashed associative data type.
  25145. \item Loose typing
  25146. \item The interpreter has no preconceptions about each sentence (valid
  25147. syntactic phrase) it will execute. In other words it knows nothing (return
  25148. type, datatype) ahead of time about the data or functions in memory.
  25149.  
  25150. \end {itemize}
  25151.  
  25152. These languages are evaluated in terms of the three things that any
  25153. programmer desires from a language: power, speed, and ease of use. Power
  25154. means a wealth of libraries for any task needed resulting in less time
  25155. required for developing/protoyping software. Speed means execution speed.
  25156. Ease of use includes how well documented the language is, how 
  25157. much support there is for problems with the language, and how cleanly
  25158. extensible the language is.
  25159.  
  25160.  
  25161.  
  25162. \section {The Languages}
  25163.  
  25164.  
  25165.  
  25166. \subsection {Lisp: Emacs version}
  25167. The Emacs Lisp editor has a core of functions including an interpreter
  25168. written C to return Lisp Objects. On top of this a number of Lisp Functions
  25169. for common tasks such as editing, buffering, process control, string
  25170. handling, user interaction/input completion, and mathematics have been
  25171. coded in C.  
  25172.  
  25173. As a result, virtually Anything Emacs does is done by a callable lisp
  25174. function which means you can write programs to take advantage of this
  25175. power. 
  25176.  
  25177. But you can only do it inside of Emacs Lisp for
  25178. the most part. The two work arounds are: (1) use emacs-server.el which
  25179. allows Emacs to send/receive on sockets, message queues and pipes or (2)
  25180. use emacs server mode. (3) For my M.S. thesis, I developed a C library
  25181. which allows Tcl and GNU Smalltalk to invoke Emacs' processes and send the
  25182. process Lisp forms for evaluation and then have the data converted back
  25183. into a format useable by the calling language.
  25184.  
  25185. Emacs can interact with other programs is through its batch mode
  25186. which is callable from C or shell scripts. Also, Emacs can start up
  25187. external programs and talk with them via process objects synchronously or
  25188. asynchronously. Danial LaLiberte wrote an Emacs interface to
  25189. an incremental parser that runs simultaneously with Emacs and has
  25190. bidirectional communication with Emacs.
  25191.  
  25192. You  may obtain Emacs Lisp via the following ftp site:
  25193. \begin {itemize}
  25194. \item "/anonymous@src.doc.ic.ac.uk:/pub/gnu"
  25195. \item "/anonymous@prep.ai.mit.edu:/pub/gnu"
  25196. \end   {itemize}
  25197.  
  25198.  
  25199. \subsection {Perl}
  25200. Combines the best features of awk, sed, and shell programming. The
  25201. latest version can be embedded in C programs. It is also easy to call
  25202. from the shell. 
  25203.  
  25204. Perl can be linked with external C libraries, such as curses or 
  25205. database accessing libraries, like oracle or sybase, making for 
  25206. easy access to screen-based form programs to deal with your dbase.
  25207.  
  25208. Perl may be obtained from the following ftp sites:
  25209. \begin {itemize}
  25210. \item "/anonymous@convex.com:/pub/perl"
  25211. \item "/anonymous@archive.cs.ruu.nl:/DOC"
  25212. \end   {itemize}
  25213.  
  25214.  
  25215. \subsection {Python}
  25216. An object-oriented interpreted language. Callable from C as well as the
  25217. shell. Interpretation may be sidestepped through the use of the
  25218. byte-compiler on files. Python played a major role in testing Amoeba, a
  25219. distributed operating system developed at CWI.
  25220.  
  25221. Python has been chosen as one of the extension languages for MADE, a
  25222. multimedia application development environment being designed and
  25223. built for ESPRIT (an EC programme for cooperative computer science
  25224. research) together with several European companies.
  25225.  
  25226. Several companies have significant interest in Python for
  25227. products and/or internal development; amongst these are XVT, Sunrise
  25228. Software, Island Software, VI Corporation, and Cabletron.
  25229.  
  25230. It's central goal is to provide the best of both worlds:
  25231. the dynamic nature of scripting languages like Perl/TCL/REXX,
  25232. but also support for general programming found in the more
  25233. traditional languages like Icon, C, Modula,...
  25234.  
  25235. Python resembles other scripting languages a number of ways:
  25236.     - dynamic, interpretive, interactive nature
  25237.     - no explicit compile or link steps needed
  25238.     - no type declarations (it's dynamically typed)
  25239.     - high-level operators ('in', concatenation, etc)
  25240.     - automatic memory allocation/deallocation (no 'pointers')
  25241.     - high level objects: lists, tuples, strings, associative arrays
  25242.     - programs can construct and execute program code using strings
  25243.     - very fast edit/compile/run cycle; no static linking
  25244.     - well-defined interface to and from C functions and data
  25245.     - well-defined ways to add C modules to the system and language
  25246.  
  25247. Python's features that make it useful for serious programming:
  25248.     - it's object-oriented;  it has a simplified subset of
  25249.       C++'s 'class' facility, made more useful by python's
  25250.       dynamic typing;  the language is object-oriented from
  25251.       the ground up (rather than being an add-on, as in C++)
  25252.  
  25253.     - it supports modules (imported packages, as in Modula-3);
  25254.       modules replace C's 'include' files and linking, and allow
  25255.       for multiple-module systems, code sharing, etc.;
  25256.  
  25257.     - it has a good exception handling system (a 'try' statement,
  25258.       and a 'raise' statement, with user-defined exceptions);
  25259.  
  25260.     - it's orthogonal;  everything is a first-class object in the
  25261.       language (functions, modules, classes, class instance methods...)
  25262.       and can be assigned/passed and used generically;
  25263.  
  25264.     - it's fairly run-time secure;  it does many run-time checks
  25265.       like index-out-of-bounds, etc., that C usually doesn't;
  25266.     - it has general data structuring support;  Python lists are
  25267.       heterogeneous, variable length, nestable, support slicing,
  25268.       concatenation, etc., and come into existance and are reclaimed
  25269.       automatically;  strings and dictionaries are similarly general;
  25270.  
  25271.     - it's got a symbolic debugger and profiler (written in python,
  25272.       of course..), and an interactive command-line interface;
  25273.       as in Lisp, you can enter code and test functions in isolation,
  25274.       from the interactive command line (even linked C functions);
  25275.  
  25276.     - it has a large library of built-in modules;  it has support
  25277.       for sockets, regular expressions, posix bindings, etc.
  25278.  
  25279.     - it supports dynamic loading of C modules on many platforms;
  25280.  
  25281.     - it has a readable syntax;  python code looks like normal
  25282.       programming languages;  tcl and perl can be very unreadable
  25283.       (IMHO; what was that joke about Perl looking the same after
  25284.       rot13..);  python's syntax is simple, and statement based;
  25285.  
  25286. Of course, Python isn't perfect, but it's a good compromise betweem
  25287. scripting languages and traditional ones, and so is widely applicable.
  25288. 'Perfect' languages aren't always useful for real-world tasks (Prolog,
  25289. for example), and languages at either extreme are not useful in the other
  25290. domain (C is poor for shell coding and prototyping, and awk is useless
  25291. for large systems design; Python does both well).
  25292.  
  25293. For example, I've used Python successfully for a 4K line expert system
  25294. shell project; it would have been at least twice as large in C, and would
  25295. have been very difficult in TCL or Perl.
  25296.  
  25297. Python uses an indentation-based syntax which may seem unusual at first
  25298. to C coders, but after using it I have found it to be very handy, since
  25299. there's less to type.  [I now forget to type '\}' in my C code, and am
  25300. busy calculating how much time I wasted typing all those '\}', 'END', etc.,
  25301. just to pander to 'brain-dead' C/Pascal compilers :-)].
  25302.  
  25303.  
  25304. Python is available from the following sites:
  25305.  
  25306. \begin {itemize}
  25307. \item "/anonymous@ftp.cwi.nl:/pub"
  25308. \item "/anonymous@gatekeeper.dec.com:/pub/plan/python/cwi"
  25309. \item "/anonymous@ftp.uu.net:/languages/python"
  25310. \item "/anonymous@wuarchive.wustl.edu:/pub"
  25311. \end   {itemize}
  25312.  
  25313. To get on the mailing list mail {\tt python-list-request@cwi.nl}.
  25314.  
  25315.  
  25316.  
  25317. \subsection {Tcl}
  25318. Tcl itself is a deceptively simple string-oriented language intended to be
  25319. transparently extensible in C or Tcl. Tcl has been extended to make use of
  25320. many typically non-unified systems and protocols such as SQL, curses,
  25321. ToolTalk, and most notably, X-Windows. Tcl can do a 5 page X-Windows program in
  25322. *2* lines and more.  
  25323.  
  25324. >From having programming in Tcl extensively, I have noticed two very useful
  25325. aspects about Tcl. First, Tcl is a modeless language, meaning that it
  25326. does not enforce any particular programming paradigm such as
  25327. functional, logic, or object-oriented. As a result, it is very easy to
  25328. switch between any of the above modes during the same program
  25329. execution. Two well-designed object systems (incr Tcl and TheObjects)
  25330. exist for Tcl. The author is currently finding embedding a Prolog
  25331. interpreter into Tcl a simple task (much easier than the Pascal
  25332. pseudo-code).  The second thing about Tcl is that all commands and
  25333. data (with the exception of associative arrays and C source code for
  25334. use in Tcl) are nothing but strings. As a result, programs and data
  25335. are highly interchangeable. Tcl contains 3
  25336. datatypes -- a word (a collection of ascii characters), a list (a
  25337. whitespace separated collection of words) and associative arrays.
  25338. Since lists are nothing but strings, they are mutable by both string
  25339. and ``list'' operations, where list operations are nothing but string
  25340. operations which regard whitespace as word separators.
  25341.  
  25342. Tcl has been ported to most unix-like systems (Sun, DEC, Silicon Graphics,
  25343. System 5, the free Intel unix-alikes, etc.), VMS, Amiga, MS-DOS, MACOS,
  25344. GS/OS, Vxworks, and a number of other operating systems.
  25345.  
  25346.  
  25347. Tcl is available at the following ftp sites:
  25348. \begin {itemize}
  25349. \item "/anonymous@sprite.berkeley.edu:/tcl"
  25350. \item "/anonymous@harbor.ecn.purdue.edu:/pub/tcl"
  25351. \end   {itemize}
  25352.  
  25353.  
  25354. \section {Acknowledgements}
  25355.  
  25356. \begin {description}
  25357.  
  25358. \item [Per Abramsen] For his source code contributions.
  25359.  
  25360. \item [Tom Christiansen] For his Perl source code for this paper and also
  25361. his general comments.
  25362.  
  25363. \item [Lance Ellinghouse] For his Python source code and critique of this
  25364. paper. 
  25365.  
  25366. \item [Bill Janssen] For his additions to this paper.
  25367.  
  25368. \item [Daniel Laliberte] For his excellent work with the Free Software
  25369. Foundation including co-authorship of the Emacs Lisp Reference Manual and
  25370. also his comments on this paper.
  25371.  
  25372. \item [Karl Lehenbauer] For co-authorship of Extended Tcl and for his
  25373. source code contributions to this paper.
  25374.  
  25375. \item [Michael Winikoff] for his critique.
  25376.  
  25377. \item [Larry Virden] For his tireless work on the Tcl FAQ (which was the
  25378. first time I had ever heard of Tcl) and his critque of this paper.
  25379.  
  25380. \end   {description}
  25381.  
  25382.  
  25383. \subsection {Important Papers / People}
  25384.  
  25385. \begin {description}
  25386.  
  25387. \item [Catalog of Free Compilers and Interpreters] This document attempts
  25388. to catalog freely availiable compilers,
  25389. interpreters, libraries, and language tools. Available via anonymous ftp
  25390. from: 
  25391.  
  25392. {\tt /anonymous@idiom.berkeley.ca.us:/pub/compilers-list/FreeCompilers*}
  25393.  
  25394. \item [Language List] Collected information on about 2100 computer
  25395. languages, past and present. Available from 
  25396.  
  25397. {\tt /anonymous@primost.cs.wisc.edu:pub/comp.compilers/LanguageList*}
  25398.  
  25399. {\tt /anonymous@idiom.berkeley.ca.us: pub/compilers-list/LanguageList*}.
  25400. You can also access a hypertext version of the Language List via xmosaic
  25401. from the HTTP server: {\tt http://cui\_www.unige.ch}
  25402.  
  25403.  
  25404. \end {description}
  25405.  
  25406. \section {The Future}
  25407. \subsection {More Languages}
  25408.  
  25409.  
  25410. \subsection {More Examples and Tests}
  25411.  
  25412.  
  25413. \subsection {Multiple Computer Language Programming}
  25414.  
  25415. Expression of mathematics in Tcl is cumbersome yet X11 graphics is very
  25416. very easy. Perl has excellent string and manipulation tools and a ton of
  25417. sysadmin utilities written in it.
  25418.  
  25419. The bottom line is that all of these languages have powerful tools ready
  25420. to use. Each language also has its weak points. Instead of being stuck
  25421. in each language and slaving through its weakness (or lack of a certain
  25422. utility), one should be able to fire up an interpreter in any of these
  25423. other languages and let it perform on it strong points and return the
  25424. answer.
  25425.  
  25426. I expect this type of hybrid programming to become almost necessary with
  25427. excellent packages and large being written for each langauge. 
  25428. For my M.S. Thesis, I developed a C library which allows for simulataneous
  25429. programming in C, Emacs Lisp, Smalltalk and Tcl.
  25430.  
  25431.  
  25432. \subsection {More Software}
  25433. A trans-language browser. If you see that a Perl script has been
  25434. written to traverse a directory tree and count the number of files
  25435. ending in .o whose age is more than 20 days but you are not a Perl
  25436. programmer, that Perl script should become and OBJECT to which you SEND
  25437. a message to get that work done.
  25438.  
  25439. \subsection {Is Interpreted Really Slower?}
  25440.  
  25441.  
  25442. I some cases compiled code is really compiled code performing certain
  25443. interpretive tasks. As a result, an interpreted language (which is really
  25444. just a C program performing syntax-directed tasks) may perform as
  25445. fast or faster than compiled code trying to perform interpreted tasks.
  25446.  
  25447. Although not currently detailed in this survey, an excellent example of a
  25448. language optimized for particular interpreted tasks is Prolog. Consider a
  25449. program typically done in an introductory programming class: maintain a
  25450. student gradebook and be able to collect information from the gradebook
  25451. based on certain criteria such as year in school and overall average.
  25452. Analysis of this program reveals three major tasks: {\it hashing} of
  25453. students by a unique key, {\it searching} the hashed space, 
  25454. {\it collecting} related students based on specified criteria. To anyone
  25455. experienced in Prolog, there is no question that a Prolog program to
  25456. perform this task will be far shorter than the corresponding C program. In
  25457. addition, because there is only one method for handling each of the major
  25458. tasks of the program, the Prolog interpreter can make use of its optimized
  25459. methods for handling each of these tasks. \footnote{The only method of
  25460. hashing is by assertion of clauses. The only method of
  25461. searching the clauses in a Prolog program is by unification. The only
  25462. method of collection of numerous clauses is by recursive list generation.}
  25463.  
  25464. Therefore in cases where one is trying to model a changing, evolving,
  25465. non-deterministic situation, an interpreted language is best used.
  25466.  
  25467.  
  25468. \part {Power}
  25469.  
  25470.  
  25471.  
  25472.  
  25473.  
  25474.  
  25475.  
  25476.  
  25477. \chapter {Graphics}
  25478.  
  25479. \section{Emacs Lisp} 
  25480.  
  25481. \section{Perl}
  25482.  
  25483. \section{Python}
  25484.  
  25485. \subsection {Significant Extensions}
  25486.  
  25487. Python has full support for both X11R4/Motif and through the use of the
  25488. STDWIN paradigm, the same source code 
  25489. can do graphics in the following systems:
  25490.  
  25491. \begin{enumerate}
  25492. \item X-windows
  25493. \item Macintosh using either Think C 4.02 or MPW C 2.02
  25494. \item Atari ST
  25495. \item DOS
  25496. \item Silicon Graphics SGI workstations
  25497. \end{enumerate}
  25498.  
  25499. This approach allows flexibility but means that no one graphics system's
  25500. potential is maximized. 
  25501.  
  25502. \section{Tcl}
  25503.  
  25504.  
  25505. \subsection {Significant Extensions}
  25506. \begin{description}
  25507. \item[TD\_CAD] A drawing program
  25508. \item[VOGLE] 3D rendering, fonts
  25509. \item[TSipp] Tcl interface to the SIPP 3-D rendering package.
  25510. \end{description}
  25511.  
  25512.  
  25513. \chapter {User Interface Building}
  25514.  
  25515.  
  25516. \section {Emacs Lisp} 
  25517. Emacs 19 has popup menus and multiple windows.
  25518.  
  25519. The ability to synchronously and asynchronously control processes it to use Tcl's WAFE.
  25520.  
  25521.  
  25522. \section {Perl}
  25523. Again none interally, but the author of WAFE, the tcl/tk graphic
  25524. interpreter wrote all of his example programs in Perl (wafemail,
  25525. wafenews, wafeftp).
  25526.  
  25527. Certainly perl can issue external commands (inferior processes in lisp
  25528. parlance).  There is also a version of guiperl I've seen Larry demo
  25529. for me, so there's at least proof-of-concept that you can link in 
  25530. the X libs.  Whether it will come out with perl5 I don't know.
  25531.  
  25532.  
  25533.  
  25534. \section {Python}
  25535. STDWIN also handles user interface development tasks.
  25536.  
  25537.  
  25538. \subsection {Significant Extensions}
  25539. \begin {description}
  25540. \item [EZD]  Joel Bartlett's very nice WAFE-style system (very nice, check
  25541. it out!). *** More comments are needed here... ***
  25542. \end {description}
  25543.  
  25544. \section {Tcl}
  25545. Power is the word. Tcl has numerous user-contributed widgets including
  25546. photo widgets, bar graph widgets, editable text widgets, pixmap widgets and
  25547. much more.  
  25548.  
  25549. \subsection {Significant Extensions}
  25550. \begin{description}
  25551. \item[XF] Menu-driven user interface builder
  25552. \item[TkSteal] Allows for a Tk program to have an Emacs widget or a
  25553. Ghostscript widget.
  25554. \item[Pixmap] A color pixmap editor written in Tcl/Tk
  25555. \item[PhotoWidget] A photo widget for Tk.
  25556. \item[WAFE] {\it W}idget {\it A}thena {\it F}ront {\it E}nd. Implemented in
  25557. Tcl, this package allows for the same generic graphic commands to be used
  25558. to develop user interfaces regardless of what language you are programming
  25559. in. All you need to do is interface to WAFE from your language. 
  25560. \item[xy-graph] Includes a Hypertext widget. This means that regardless of
  25561. what stream of information comes at your Tcl program, you can create
  25562. windows and paths through the stream on the fly. A major example of the
  25563. hypertext widget is Joseph Wang's World Wide Web Hypertext browser.
  25564. \end{description}
  25565.  
  25566.  
  25567.  
  25568. \chapter {String Handling}
  25569.  
  25570. \section {Emacs Lisp}
  25571. Strong. Many good string handling functions for operation on buffers as
  25572. well as string. Search replace backward and forward with regexps. Many
  25573. good string handling functions are found in tree-dired.el in gmhist*.el.
  25574. As well as in ange-ftp.el.
  25575.  
  25576. \section {Perl}
  25577. Very strong.
  25578.  
  25579. String-handling is one of Perl's strongest features: they are quite
  25580. powerful and extensive.  Strings can be as long as you want, and contain
  25581. binary data and nulls.  This works:
  25582. \begin{verbatim}
  25583.     $kernel = `cat /vmunix`;
  25584. \end{verbatim}
  25585.  
  25586. Perl has a wealth of string-accessing functions, including matching,
  25587. substitution, transliteration, splitting, and direct substring accessing.
  25588. Strings and numbers are interchangeable.  The regexps are a superset of
  25589. other regexp syntaxes, with extensions.  Parsing is very easy:
  25590. \begin{verbatim}
  25591.     ($name, $number, $host) = /(\w+)=(\d+)( from @(\w+))?/;
  25592. \end{verbatim}
  25593. Subexpressions can nest, and be arbitrarily deep: you don't have
  25594. to stop with \\9, but can keep going.
  25595.  
  25596. Perl's substitution operator works like sed's:
  25597. \begin{verbatim}
  25598.     s/foo/bar;
  25599. \end{verbatim}
  25600. or
  25601. \begin{verbatim}
  25602.     $a =~ s/foo/bar/g;
  25603. \end{verbatim}
  25604. but can do much more, like:
  25605. \begin{verbatim}
  25606.     s/(\d+)/sprintf("0x%08x", $1)/ge;
  25607. \end{verbatim}
  25608. to find all the numbers in the pattern space and replace them 
  25609. with the hex representation of the same.  It has other powerful
  25610. features I don't have time or space to go into.
  25611.  
  25612. Perl also lets you treat strings as raw bitwise data, so 
  25613. \begin{verbatim}
  25614.     substr($a,0,3) &= "\177\177\177";
  25615. \end{verbatim}
  25616. would clear the high bits on the first 3 bytes of \$a.  You
  25617. can also access strings bitwise, say, to check the $2456$th bit 
  25618. of a string.
  25619.  
  25620. \section {Python}
  25621. It has a string module, regexp module, and regsub module. It has all the string
  25622. search and replace capabilities of Emacs.
  25623.  
  25624. \section {Tcl}
  25625. Everything in Tcl is a string. It is very easy to map certain
  25626. string-intensive applications to Tcl. For example, I wrote a program to
  25627. do parallel library database searches in Tcl in about two weeks. Ranking
  25628. the 4 languages in terms of how easy it would have been: Tcl, Python,
  25629. Emacs, and I cant say about Perl because I gave up on Perl quickly after
  25630. buying the book and seeing all those registers and the confusing
  25631. context-intensive syntax. 
  25632.  
  25633.  
  25634. \chapter {Unix / Internet Programming}
  25635.  
  25636.  
  25637. \section {Emacs Lisp}
  25638. Has specialized modes for controlling Common Lisp and other lisps to
  25639. facilitate debugging, execution, and programming. Has shell modes with
  25640. command history. Has an excellent ftp program (ange-ftp). Can
  25641. asynchronously or synchronously call the shell and store the output in a
  25642. buffer or string. Can filter output from a process. However, the
  25643. filtering is somewhat hairy because you cannot be sure of the packet
  25644. size that the data will arrive in. In other words, it is easy to open a
  25645. pipe with Perl/Python/Tcl and just read lines at a time but you have to
  25646. write an accumulator function to do this in Emacs Lisp. However, the
  25647. interactor mode for GNU Smalltalk has an excellent accumulator function
  25648. that you could use in your own code. 
  25649.  
  25650. Dan LaLiberte disagrees with the difficulty of accumulating input from a
  25651. process that Emacs has spawned. He says: ``An accumulator of whole lines
  25652. could be written in Emacs Lisp with not much problem.  I'd be surprised if
  25653. no one has done so yet.'' However, until I see it, I stand by my above
  25654. statement. 
  25655.  
  25656. \subsection {Significant Extensions}
  25657. \begin {description}
  25658. \item[VM] A mail reader that does everything that I need. 
  25659. \item[Gnus] A Usenet reader that can save articles to mail folders for
  25660. later recall. I often save articles in Gnus and later read them using VM.
  25661. \item[Ange-FTP] An excellent ftp utility which allows transparent
  25662. file access/modification with the ease of a few keystrokes.
  25663. \item[Tree Dired] Allows you to scroll through directories and copy, edit,
  25664. remove, view files. And more
  25665. \end {description}
  25666.  
  25667.  
  25668.  
  25669. \section {Perl}
  25670. Perl has all the process control primitives available to you from C, plus
  25671. higher level constructs as well.  It's easy to open a pipe to or from
  25672. another process.  You can even open a pipe to an implicitly forked version
  25673. of yourself.   Standard Perl library routines allow bidirectional pipes
  25674. and running things over a pty via a package that works much like Don
  25675. Libes's Expect, save that it uses Perl instead of tcl as an extension
  25676. language.  Perl can also access all the socket and ipc functions on your
  25677. system without calling a program to do it.
  25678.  
  25679. \subsection {Significant Extensions}
  25680. ??**??
  25681.  
  25682. \section {Python}
  25683. Python's process control is at least as strong as Perl's.
  25684. In addition, it supports threads (!), so that some of the operations
  25685. you have to do in another process, using Tcl or Perl, you can do
  25686. in another thread, in Python.
  25687.  
  25688. Python has a Posix and a generic OS module to handle this type of thing.
  25689.  
  25690.  
  25691. \subsection {Significant Extensions}
  25692. \begin {description}
  25693. \item[ftplib.py]
  25694. \item[nntplib.py]
  25695. \end {description}
  25696.  
  25697. \section {Tcl}
  25698.  
  25699.  
  25700. \subsection {Significant Extensions}
  25701.  
  25702. \begin {description}
  25703. \item[Expect] Due to an extension added to Tcl, process control in Tcl is a
  25704. snap. A Tcl package by Don Libes called Expect allows 
  25705. the programmer to specify a set of expected regexps from the process and
  25706. what to do upon the receipt of the process output. Several of his papers
  25707. including "expect: Curing Those Uncontrollable Fits of Interaction"
  25708. available in postscript format for anonymous ftp from durer.cme.nist.giv
  25709. in pub/expect. 
  25710.  
  25711. \item[Artcls] A graphic Usenet newsreader.
  25712. \item[TkWWW] A Tk world-wide web browser.
  25713. \end {description}
  25714.  
  25715. \chapter {Other}
  25716.  
  25717.  
  25718. \section {Emacs Lisp}
  25719.  
  25720. \begin{description}
  25721. \item[Folding Mode] Allows for hierarchical editing of structured text
  25722. files. I use it all the time. You can move through and edit any document
  25723. (program, LaTeX file, whatever) much faster using folding mode.
  25724. \item[EDB]  full featured database
  25725. \item[AUC-TeX] Allows you to do anything you would want to do with
  25726. TeX/LaTeX from an Emacs buffer quickly and easily.
  25727. \item[Calc] The poor man's Mathematica. Includes rewrite rules and
  25728. functionality on the order of the HP-28.
  25729. \item[VIP] vi emulation for emacs
  25730. \item[Calendar/Diary] Calendar and appointment manager within Emacs
  25731. \item[Hyperbole] Extensible hypertext management system within Emacs. 
  25732. \end{description}
  25733.  
  25734.  
  25735. \section {Perl}
  25736. Having been publicly available for six years now, Perl has a truly huge
  25737. body of code already written for it.  I couldn't begin to document all of
  25738. them.  More than any other language listed herein, it is the tool of
  25739. choice for Unix system administrators.  Perl comes with a symbolic
  25740. debugger, a bunch of libraries, various tools, and and numerous example
  25741. programs, but that's just the start.  
  25742.  
  25743.  
  25744.  
  25745. \section {Python}
  25746.  
  25747. \begin {description}
  25748.  
  25749. \item[CMIFed] An authoring environment for transportable, distributed
  25750. hypermedia presentations.  It consists of at least 20,000 lines of
  25751. Python and 4,000 lines of C extensions.  (A paper by Guido von Rossum and
  25752. others about it has appeared in the proceedings of the ACM Multimedia
  25753. '93 conference.)
  25754.  
  25755. \item[MCC] A teleconferencing tool written in Python. Still under
  25756. development.
  25757.  
  25758. \end {description}
  25759.  
  25760. \section {Tcl}
  25761.  
  25762. \begin {description}
  25763. \item[Objectify] Turns C++ classes into Tcl objects.
  25764. \end {description}
  25765.  
  25766. \chapter {Sample Programs}
  25767.  
  25768.  
  25769. \section {User Interface Design}
  25770.  
  25771. \subsection {Hello, world}
  25772. Write a program to run under X-Windows which opens a
  25773. window and prints {\tt "Hello, World"} in it. Those interested in
  25774. highly portable graphic/user interface software should note that the only
  25775. language capable of doing this program on a graphic windowing system beyond
  25776. X-Windows is Python.
  25777.  
  25778. %%%4.1.    \subsection {Emacs Lisp}
  25779.  
  25780. \subsubsection {Emacs Lisp}
  25781. \begin{verbatim}
  25782. (defun hello-world ()                   ; FSF Emacs 19 only.
  25783.   ``Open new frame with a friendly greeting.''
  25784.   (switch-to-buffer-other-frame ``*hello world*'')
  25785.   (insert ``Hello, World''))
  25786. \end{verbatim}
  25787.  
  25788. %%%4.2.    \subsection {Perl}
  25789.  
  25790. \subsubsection {Perl}
  25791. \begin{verbatim}
  25792. I'd just talk to Wafe or Stdwin.  Or call xterm. :-)
  25793.  
  25794. \end{verbatim}
  25795.  
  25796.  
  25797. \subsubsection {Tcl}
  25798.  
  25799. \begin{verbatim}
  25800.  
  25801. button .hello -text {Hello, World} -command {exit}
  25802. pack append . .hello {top}
  25803.  
  25804. \end{verbatim}
  25805.  
  25806.  
  25807. \section {String Handling}
  25808.  
  25809. \subsection {String Test}
  25810. Given a file with 4 occurrences of the string "Hello Bob" find the file,
  25811. replace the last 3 occurrences of "Hello Bob" with "Hi James" and save
  25812. the file. The double quotation marks are for delineation purposes only.
  25813.  
  25814.  
  25815.  
  25816. \subsubsection {Emacs Lisp}
  25817. \begin{verbatim}
  25818. (defun Bob-meet-James (file)
  25819.   ``Replace all `Hello Bob' with `Hi James' in FILE except the first.''
  25820.   (save-excursion
  25821.     (find-file file)
  25822.     (goto-char (point-min))             ; We might already be editing it...
  25823.     (search-forward ``Hello Bob'')
  25824.     (while (search-forward ``Hello Bob'' nil t)
  25825.       (replace-match ``Hi James''))
  25826.     (save-buffer)))
  25827. \end{verbatim}
  25828.  
  25829.  
  25830.  
  25831.  
  25832. \subsubsection {Perl}
  25833. \begin{verbatim}
  25834. # the orig file will be in file.BAK -- if you don't want a backup,
  25835. # use just -i.
  25836.  
  25837. # remember that s//foo/ will match the last match
  25838.  
  25839. perl -i.BAK -p -e '/Hello Bob/ && $seen++ && s//Hi James/g'
  25840.  
  25841. or 
  25842.     perl thisprog < file.in > file.out
  25843.  
  25844.  
  25845.     #!/usr/bin/perl
  25846.     while (<>) {
  25847.     if (/Hello Bob/ && $seen++) {
  25848.         s//Hi James/g;
  25849.     } 
  25850.     print;
  25851.     } 
  25852. \end{verbatim}
  25853.  
  25854.  
  25855.  
  25856.  
  25857. \subsubsection {Python}
  25858. \begin{verbatim}
  25859.  
  25860. #! /usr/local/bin/python
  25861. import strop
  25862.  
  25863. fp = open('testFile','r')
  25864. lines = fp.readlines()  # read all lines in and seperate on \n's
  25865. fp.close()
  25866. fp = open('testFile','w')
  25867. for indx in range(0,len(lines)-4,4):
  25868.     fp.write('\n'+lines[indx]+'::'+linex[indx+1]+'::'+lines[indx+2])
  25869. fp.close()
  25870.  
  25871. \end{verbatim}
  25872.  
  25873. OR
  25874.  
  25875. \begin{verbatim}
  25876. Hello, Bob (I think; I didn't actually try it):
  25877.  
  25878.         #!/usr/bin/python
  25879.  
  25880.         def sub_in_file(file):
  25881.                 import regsub
  25882.                 import string
  25883.  
  25884.                 seen = None
  25885.                 fp = open(file, 'r+')
  25886.                 lines = fp.readlines()
  25887.                 fp.seek(0, 0)
  25888.                 for line in lines:
  25889.                         if seen:
  25890.                                 regsub.gsub('Hello Bob', 'Hi James', line)
  25891.                         else:
  25892.                                 seen = (string.find (line, 'Hello Bob') >=
  25893. 0)
  25894.                         fp.write(line)
  25895.  
  25896.         import sys
  25897.  
  25898.         sub_in_file(sys.argv[1])
  25899.  
  25900. \end{verbatim}
  25901.  
  25902.  
  25903.  
  25904.  
  25905. \subsubsection {Tcl}
  25906.  
  25907. \begin{verbatim}
  25908.  
  25909.      set fdIn [open testFile r]
  25910.      set contents [read $fdIn]
  25911.      regexp -indices "Hello Bob" $contents matches
  25912.      regsub -all "Hello Bob" \
  25913.        [string range $contents [expr [lindex $matches 1]+1] end] \
  25914.        "Hi James" result
  25915.      close $fdIn
  25916.      set fdOut [open testFile w]
  25917.      puts $fdOut [string range $contents 0 [lindex $matches 1]]$result \
  25918.        nonewline
  25919.      close $fdOut
  25920.      exit
  25921.  
  25922. \end{verbatim}
  25923.  
  25924.  
  25925.  
  25926.  
  25927. \subsection {String Test 2}
  25928. A lengthy file has been entered with records of the form:
  25929. \begin{verbatim}
  25930. <\n>NAME<\n>ADDRESS<\n>PHONE<\n>----------
  25931. \end{verbatim}
  25932. where \begin{verbatim}<\n>\end{verbatim} represents a line feed and the
  25933. \begin{verbatim}----------- \end{verbatim} is used to
  25934. separate records. Convert all entries in the file to a new format of
  25935. the form:
  25936. \begin{verbatim}<\n>NAME::ADDRESS::PHONE}
  25937. \end{verbatim}
  25938.  
  25939.  
  25940.  
  25941. \subsubsection {Emacs Lisp}
  25942. \begin{verbatim}
  25943. (defun newline-to-double-colon ()
  25944.   ``Convert current buffer from old style to new style address book
  25945. format.''
  25946.   (goto-char (point-min))
  25947.   (while (re-search-forward
  25948.           ``\n\\([^\n]*\\)\n\\([^\n]*\\)\n\\([^\n]*\\)\n----------'' nil t)
  25949.     (replace-match ``\n\\1::\\2::\\3'')))
  25950. \end{verbatim}
  25951.  
  25952.  
  25953.  
  25954.  
  25955. \subsubsection {Perl}
  25956.  
  25957. \begin{verbatim}
  25958.  
  25959.     #!/usr/bin/perl
  25960.     $/ = "\n----------";      # set record separator
  25961.     while (<>) {        # read a record
  25962.     s!$/$!!;          # remove record terminator
  25963.     s/^\n//;        # trim first line feed
  25964.     s/\n/::/g;        # turn rest into double dolon
  25965.     print "\n";        # new record starts with \n
  25966.     print;            # output current pattern space
  25967.     } 
  25968.  
  25969. # Did you know that the last record in the file will no longer
  25970. # have a terminating newline?  Make sure the others get this right.
  25971. \end{verbatim}
  25972.  
  25973.  
  25974.  
  25975.  
  25976. \subsubsection {Tcl}
  25977.  
  25978. \begin{verbatim}
  25979.  
  25980.      set fdIn [open testFile r]
  25981.      set contents [read $fdIn]
  25982.      regsub -all "^\n" $contents "" contents
  25983.      regsub -all "\n" $contents "::" contents
  25984.      regsub -all "::----------::" $contents "\n" contents
  25985.      close $fdIn
  25986.      set fdOut [open testFile w]
  25987.      puts $fdOut $contents nonewline
  25988.      close $fdOut
  25989.      exit
  25990.  
  25991.  
  25992. \end{verbatim}
  25993.  
  25994.  
  25995. \subsection {Parsing a Prolog Structure for Logical Variables}
  25996.  
  25997. A Prolog structure consists of a {\it functor,} open parenthesis, a series of
  25998. comma-separated {\it terms,} which may be either constants or logical
  25999. variables and a close parenthesis. Here is an example of a structure with a
  26000. constant named {\tt baker} and two logical variables named {\tt CHARLIE}
  26001. and {\it FRANCE}.
  26002.  
  26003. \begin {verbatim}
  26004. able(baker,CHARLIE,FRANCE)
  26005. \end{verbatim}
  26006.  
  26007. Write a procedure that when given a list of structures (structures separated by
  26008. whitespace or tabs) will print out all of the logical variables in each
  26009. structure, also printing out each corresponding functor. For example, given
  26010. the above structure the output would be:
  26011.  
  26012. \begin {verbatim}
  26013. functor: able  logical variables: CHARLIE FRANCE
  26014. \end{verbatim}
  26015.  
  26016. \subsubsection {Emacs Lisp}
  26017. \subsubsection {Perl}
  26018. \subsubsection {Python}
  26019.  
  26020.  
  26021. \subsubsection {Tcl}
  26022.  
  26023. \begin {verbatim}
  26024.  
  26025. proc datalog_logical_variables_in_clause {clause} {
  26026.     foreach structure $clause {
  26027.     set S [string trimright $structure ")"]
  26028.     set F [lrange [split $S "("] 1 end]
  26029.     set S [split $F ","]
  26030.     puts "functor: [lindex $F 0] logical variables: $S"
  26031.     }
  26032. }
  26033.  
  26034. \end{verbatim}
  26035.  
  26036.  
  26037. \subsection {Hofstadter's MIU Formal System}
  26038.  
  26039. Basically this is a test of string concatenation. We start with one initial
  26040. string and drop it in a bucket (any appropriate datatype from your language
  26041. is fine). Then we apply each applicable rule of the system to all strings
  26042. in the bucket and add the results of each application to the bucket. We
  26043. perform the rule application five times.
  26044.  
  26045. The only characters in a string are M, I, and U (just the letters not the
  26046. commas). 
  26047.  
  26048. Here are the rules:
  26049.  
  26050. \begin {enumerate}
  26051. \item If a string S has I as its last letter, you can add on a U at the end
  26052. of S, creating a new string. Example: $  S == MII. S_{new} == MIIU.  $
  26053. \item Suppose string S is of the form Mx. Then you may create a string of
  26054. the form Mxx from S. Example: $  S == MIU. S_{new} == MIUIU. $
  26055. \item If the substring III appears in S, then III may be replaced by U.
  26056. Multiple occurrences of III result in multiple new strings. Example: $
  26057. S == MIIII. S_{new1} == MIU. S_{new2} == MUI $
  26058. \item If the substring UU occurs inside S, then the first occurence may be
  26059. deleted. Example: $ S == MUU. S_{new} == M. $
  26060. \end {enumerate}
  26061.  
  26062.  
  26063.  
  26064. \subsection {Filtering a Printerleaf File}
  26065.  
  26066.  
  26067.  
  26068. I once had a dump of a file of Interleaf which looked like this:
  26069.  
  26070. \begin {verbatim}
  26071.  
  26072. \\377Parallelized\\266the\\266expectation
  26073. \\266maximization\\266algorithm.\\266This\\266algorithm\\266is\\266used
  26074.  
  26075. \end{verbatim}
  26076.  
  26077. I wanted to do the following:
  26078.  
  26079. \begin {itemize}
  26080. \item Simply output alphanumeric characters
  26081. \item Simply output linefeeds
  26082. \item Otherwise output a space
  26083. \end {itemize}
  26084.  
  26085. So I wrote the following C program:
  26086.  
  26087. \begin {verbatim}
  26088. #include <stdio.h>
  26089.  
  26090. main (int argc , char *argv[]) {
  26091.  
  26092.   FILE 
  26093.     * fp ;
  26094.   char
  26095.     c ;
  26096.  
  26097.   fp = fopen (argv[1],"r") ;
  26098.  
  26099.   printf ("argv[1]: %s \n", argv[1]) ;
  26100.  
  26101.   while ((c = getc (fp)) != EOF)
  26102.     {
  26103.  
  26104.       if (isalnum(c)) 
  26105.     {
  26106.       putchar (c) ;
  26107.     }
  26108.  
  26109.       else
  26110.     {
  26111.       if (c == 10)
  26112.         {
  26113.           putchar (c) ;
  26114.         }
  26115.       else
  26116.         {
  26117.           putchar (32) ;
  26118.         }
  26119.     }
  26120.     }
  26121.   
  26122. }
  26123.  
  26124.   
  26125.  
  26126. \end{verbatim}
  26127.  
  26128.  
  26129.  
  26130. \section {Unix/Internet Programming}
  26131.  
  26132. \subsection {Count files in a Directory}
  26133. Write a program to count the number of files in the current directory.
  26134.  
  26135.  
  26136.  
  26137. \subsubsection {Emacs Lisp}
  26138.  
  26139. \begin{verbatim}
  26140.  
  26141. (defun current-directory-size ()
  26142.   ``Number of files in the current directory.''
  26143.   (length (directory-files ``.''))
  26144.  
  26145. \end{verbatim}
  26146.  
  26147.  
  26148.  
  26149. \subsubsection {Perl}
  26150.  
  26151. \begin{verbatim}
  26152.  
  26153.     #!/usr/bin/perl
  26154.     $count = @files = <*>;
  26155.     print "Directory file count: $count\n";
  26156.  
  26157.     #!/usr/bin/perl
  26158.     $count++ while <*>;
  26159.     print "Directory file count: $count\n";
  26160.  
  26161.     #!/usr/bin/perl
  26162.     print "Directory file count:", `ls | wc -l`;
  26163.  
  26164. # those didn't have dot files.  if you want dot files,
  26165. # use <* .*> instead.
  26166.  
  26167.     #!/usr/bin/perl
  26168.     opendir(DOT, '.');
  26169.     $count = @files = readdir(DOT);
  26170.     print "Directory file count: $count\n";
  26171.  
  26172.     #!/usr/bin/perl
  26173.     opendir(DOT, '.');
  26174.     $count++ while readdir(DOT);
  26175.     print "Directory file count: $count\n";
  26176.  
  26177. \end{verbatim}
  26178.  
  26179.  
  26180.  
  26181. \subsubsection {Python}
  26182.  
  26183. \begin {verbatim}
  26184.  
  26185. def current_directory_size():
  26186.         import os
  26187.         return len(os.listdir('.'))
  26188.  
  26189. \end{verbatim}
  26190.  
  26191.  
  26192.  
  26193. \subsubsection{Tcl}
  26194.  
  26195. \begin{verbatim}
  26196.  
  26197. set count [ls | wc -l]
  26198.  
  26199. \end{verbatim}
  26200.  
  26201.  
  26202.  
  26203. \subsection {Automated FTP file transfer}
  26204.  
  26205. Transfer the file {\tt tension.tex} from the internet host 
  26206. {\tt lambda.barnes.edu} in your home directory to the internet host {\tt
  26207. calculus.au} to the directory {\tt pub/public} with the file
  26208. having the new name {\tt noneed.tex}.
  26209.  
  26210. \subsubsection {Emacs Lisp}
  26211. \begin {verbatim}
  26212. (copy-file 
  26213.     "/anonymous@lambda.barnes.edu:tension.tex" 
  26214.     "/anonymous@calculus.au:pub/public/noneed.tex")
  26215. \end{verbatim}
  26216. \subsubsection {Perl}
  26217. \subsubsection {Python}
  26218. \begin {verbatim}
  26219.  
  26220. path = 'lambda.barnes.edu:tesion.tex:tension.tex'
  26221. fetch (path)
  26222.  
  26223. \end{verbatim}
  26224.  
  26225. \subsection {Significant Extensions}
  26226. \begin {description}
  26227. \item[nntplib.py]
  26228. \item[ftplib.py]
  26229. \item[rsa/md5] encryption
  26230. \item[xdr.py] Sun's ONC XDR interface
  26231. \item[rpc.py] Sun's ONC, portmapper, TCP/IP interface (NFS, etc examples)
  26232. \item[mimetools] Tools used for MIME reading/writing of messages
  26233. \item[jpeg.py] JPEG/JFIF compression/decompression routines
  26234.  
  26235. \end {description}
  26236.  
  26237. \subsubsection {Tcl}
  26238.  
  26239. \section {Other}
  26240. \subsection {Count lines in a File}
  26241. Open up a file named {\tt bozak.foo} and print the number of lines in it to
  26242. stdout. 
  26243.  
  26244.  
  26245. \chapter {Programmer Support}
  26246.  
  26247.  
  26248.  
  26249. \section {Learning Curve for Language}
  26250.  
  26251. \subsection{Emacs Lisp}
  26252. The best. Has a debugger. Since you are in Emacs, you can immediately
  26253. test whatever you are writing. Documentation on every function and
  26254. variable in memory is available in 2 keypresses. The tags system allows
  26255. you to jump to functions and global variable declarations without
  26256. knowing which file they are in. The Usenet group {\tt gnu.emacs.help} exists.
  26257. The GNU Emacs Lisp manual exists.
  26258.  
  26259.  
  26260. \subsection{Perl}
  26261. I would say strong.  To use Perl, you only need to know a little bit to
  26262. start to use it.  The interactive debugger allows you to type any kind of
  26263. Perl code you want and get an immediate answer, as well as providing
  26264. standard sym debugger capabilities such as breakpoints, single-stepping,
  26265. and stack tracebacks.  Other tools available but not included with the
  26266. Perl src kit include profilers, tags generators, cross referencers, and
  26267. tools to assemble large Perl programs using makefiles and a lintlike
  26268. checker.  Other tools provide perl-mode for vi as well as tightly coupling
  26269. the debugger with a slave vi session that autopositions by file and line.
  26270. The newsgroup {\tt comp.lang.perl} exists. The Perl book by Larry Wall is
  26271. out. 
  26272.  
  26273. \subsection{Python}
  26274. Good.  The language is VERY regular and very powerful. You have seperate
  26275. name spaces that allow reuse and an OO design of your applications/scripts.
  26276. There are HUNDREDS of support modules you can import. There is a mailing
  26277. list that you may join by mailing {\tt guido@cwi.nl}. Several manuals for
  26278. using Python exist.
  26279.  
  26280. Note that there is a GNU Emacs mode for Python, as well as a
  26281. special subprocess mode for it.  There are a couple of debuggers
  26282. shipped with the Python library, one windowing and one
  26283. command-line-like. 
  26284.  
  26285.  
  26286. \subsection{Tcl}
  26287. The language is very consistent --- every line is
  26288. started with a command which is the name of a Tcl or C function. The
  26289. rest of the line is arguments to the Tcl or C function. The newsgroup {\tt
  26290. comp.lang.tcl} exists. The Tcl books is due out soon. A version is
  26291. currently available via anonymous ftp from 
  26292. {\tt /anonymous@harbor.ecn.purdue.edu:pub/tcl/sprite-mirror}. 
  26293.  
  26294.  
  26295. \section {Test Suite}
  26296.  
  26297. \subsection{Emacs Lisp}
  26298. Well, if you compile Emacs then all core source code that Emacs needs will
  26299. run. However one of its several hundred functions and commands that Emacs
  26300. itself does not depend on might fail when a user tries to use it and no
  26301. test suite exists for these non-core commands.
  26302.  
  26303. \subsection{Perl}
  26304. Exhaustive test suite.
  26305.  
  26306. \subsection{Python}
  26307. Exhaustive test suite
  26308.  
  26309. \subsection{Tcl}
  26310. Exhaustive test suite
  26311.  
  26312.  
  26313. \chapter{Extensibility}
  26314.  
  26315. Extensibility is the ability to add a new keyword or data type to the
  26316. language in BOTH the language and C language.
  26317.  
  26318.  
  26319.  
  26320. \section {Emacs Lisp}
  26321. Extending Emacs with new Lisp code is very easy. Writing additional C code
  26322. to be added to Emacs is tedious for several reasons:
  26323.  
  26324. \begin {enumerate}
  26325.  
  26326. \item The GNU Emacs Manual does not attempt to give comprehensive
  26327. information on how to extend Emacs in C.
  26328.  
  26329. \item You must guess at the correct size of a variable called 
  26330. {\tt PURESIZE} in order to be sure that Emacs allocates enough memory for
  26331. itself when it dumps itself with the additional source code.
  26332.  
  26333. \item The {\tt GCPRO} macros are only able to protect a maximum of 4
  26334. variables. 
  26335.  
  26336.  
  26337. \end   {enumerate}
  26338.  
  26339.  
  26340.  
  26341. \section {Perl}
  26342. I am not a Perl programmer and really have no right to say anything here,
  26343. but having bought the Perl book, I noticed that the language is very
  26344. context-sensitive and has a grammar covering several pages. In contrast,
  26345. the relation of syntax to semantics for these other languages is simple and
  26346. learnable in about 5 minutes. 
  26347.  
  26348. You can extend Perl through linking with C routines.  The example
  26349. with the perl kit explains how to do this for the curses library,
  26350. but can be done for many other applications as well.  This is adding
  26351. new function calls.
  26352.  
  26353. What you would probably do is define a package and use acccessor
  26354. functions.  I did this to allow perl user's to get at C struct and union
  26355. types to interract with C programs.  A package is semi-reminiscent of a
  26356. C++ class, perhaps best described as a protected namespace with private
  26357. and public data declarations and initialization code, as well as both
  26358. private and public functions.  I wonder how the other languages stack up
  26359. on this kind of thing.
  26360.  
  26361.  
  26362.  
  26363. \section {Python}
  26364. It is very easy to add new types (Lance Ellinghouse has added about 20 new
  26365. types of objects to Python both at the C code level as well as in Python
  26366. code. 
  26367.  
  26368. Note that unlike Perl, new Python
  26369. modules written in C can be dynamically loaded into a running
  26370. interpreter.  You don't need to relink the image.  Adding a new
  26371. datatype is very easy.  Modifying the syntax (``adding a new keyword'')
  26372. doesn't seem very easy.  There could be a macro package...
  26373.  
  26374.  
  26375.  
  26376. \section {Tcl}
  26377. Its possible and well-documented and has been down well by many
  26378. people in C.
  26379.  
  26380.  
  26381. \chapter {Other}
  26382.  
  26383. \section {Useful Extras}
  26384.  
  26385. \subsection {Compilation Mechanisms}
  26386.  
  26387. \subsection {Threads}
  26388.  
  26389.  
  26390.  
  26391. \end {document}
  26392. 
  26393. 
  26394. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  26395.     id AA27705 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 10:47:52 +0100
  26396. Received: by voorn.cwi.nl with SMTP
  26397.     id AA16242 (5.65b/3.8/CWI-Amsterdam); Thu, 28 Oct 1993 10:47:51 +0100
  26398. Message-Id: <9310280947.AA16242=guido@voorn.cwi.nl>
  26399. To: python-list@cwi.nl
  26400. Subject: Bug in "rotor" module
  26401. From: Guido.van.Rossum@cwi.nl
  26402. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  26403. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  26404. Date: Thu, 28 Oct 1993 10:47:51 +0100
  26405. Sender: Guido.van.Rossum@cwi.nl
  26406.  
  26407. People who've been using the optional built-in module "rotor" may have
  26408. noticed compiler warnings about left shifts with negative shift
  26409. counts (<<-13).  I've talked to the author and the original intention
  26410. was for these to be right shifts (>>13).
  26411.  
  26412. It is trivial to fix this, however there's a compatibility issue I'm
  26413. concerned about: the key constructed using the fixed code looks
  26414. different than the key constructed by the old, buggy code.  This means
  26415. that if you have written data to a file encrypted with the old rotor
  26416. module, you won't be able to decrypt it using the new module.
  26417.  
  26418. For me personally this isn't a problem, but I can imagine that there
  26419. are others who have used this extensively.  If this is the case for
  26420. you, please speak up!  We may provide a backward compatibility hack
  26421. for you (basically you can use <<19, or live with the compiler
  26422. warnings...).  If I don't hear from anyone, I'll just fix it and
  26423. release the next version with an incompatible rotor module.
  26424.  
  26425. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  26426. 
  26427. 
  26428. To: python-list
  26429. Subject: Bug in "rotor" module
  26430. From: Guido.van.Rossum@cwi.nl
  26431. X-Organization: CWI, Kruislaan 413, 1098 SJ Amsterdam, The Netherlands
  26432. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  26433. Date: Thu, 28 Oct 1993 10:47:51 +0100
  26434. Sender: guido
  26435.  
  26436. People who've been using the optional built-in module "rotor" may have
  26437. noticed compiler warnings about left shifts with negative shift
  26438. counts (<<-13).  I've talked to the author and the original intention
  26439. was for these to be right shifts (>>13).
  26440.  
  26441. It is trivial to fix this, however there's a compatibility issue I'm
  26442. concerned about: the key constructed using the fixed code looks
  26443. different than the key constructed by the old, buggy code.  This means
  26444. that if you have written data to a file encrypted with the old rotor
  26445. module, you won't be able to decrypt it using the new module.
  26446.  
  26447. For me personally this isn't a problem, but I can imagine that there
  26448. are others who have used this extensively.  If this is the case for
  26449. you, please speak up!  We may provide a backward compatibility hack
  26450. for you (basically you can use <<19, or live with the compiler
  26451. warnings...).  If I don't hear from anyone, I'll just fix it and
  26452. release the next version with an incompatible rotor module.
  26453.  
  26454. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  26455. 
  26456. 
  26457. Replied: Thu, 28 Oct 1993 16:18:43 +0100
  26458. Replied: "michael shiplett <michael.shiplett@umich.edu> python-list"
  26459. Received: from totalrecall.rs.itd.umich.edu by charon.cwi.nl with SMTP
  26460.     id AA08604 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 16:07:31 +0100
  26461. Received: from enchanter.ifs.umich.edu by totalrecall.rs.itd.umich.edu (5.67/2.2)
  26462.     with SMTP id AA10763; Thu, 28 Oct 93 11:07:26 -0400
  26463. Message-Id: <9310281507.AA10763@totalrecall.rs.itd.umich.edu>
  26464. To: python-list@cwi.nl
  26465. Subject: md5 module
  26466. From: michael shiplett <michael.shiplett@umich.edu>
  26467. Date: Thu, 28 Oct 1993 11:07:26 -0400
  26468. Sender: walrus@umich.edu
  26469.  
  26470. Hello,
  26471.  
  26472.   I'm new to the list & to python. I did look, but to no avail, in the
  26473. source distribution for information on the following, so I hope this
  26474. isn't something that's in a FAQ I haven't found.
  26475.  
  26476.   I am trying to compile 0.9.9 on several platforms (rs_aix32,
  26477. sun4m_412, & next_mach30). I've been able to build the rs_aix32
  26478. preliminary interpreter using gcc-2.4.5 without much difficulty (some
  26479. extra preprocessor defines & some "#ifdef _AIX").  I did, however,
  26480. have problems compiling the md5 module. I have RFC-1321 & have
  26481. successfully built & tested mddriver.
  26482.  
  26483.   Have I completely missed something while configuring or are the
  26484. following actually errors/oversights/typos?
  26485.  
  26486.   - the Makefile tells the user that md5 code is available in "md5.doc"
  26487.     rsa.com. At least as of this writing, the file is
  26488.     "//rsa.com/pub/md5.txt". This file is actually just RFC-1321.
  26489.     Perhaps reference should also be made to RFC-1321 as RFCs are
  26490.     readily available (and I assume this one is as well).
  26491.  
  26492.   - the Makefile states md5c.c is needed. The RFC contains md5c.c.
  26493.     This is also true of the object file (which the Makefile gives
  26494.     as md5.o).
  26495.  
  26496.   - global.h from the md5 code is not #included (necessary for UINT4)
  26497.  
  26498.   - md5_digest calls MD5Final with only one argument (MD5_CTX
  26499.     mdContext)
  26500.  
  26501.   - also in md5_digest, there is a reference to the "digest" member of
  26502.     mdContext (declared as above). MD5_CTX in my versions of RFC-1321,
  26503.     md5.txt, and RSAREF does not contain a digest member.
  26504.  
  26505.   - the "/* Really static, forward */" declarations in md5module.c,
  26506.     mpzmodule.c, & Fontobject.c (and probably other files which I
  26507.     didn't use) do not work. Gcc creates the .o but the AIX ld
  26508.     says the symbols are not defined. AIX cc complains about MD5type
  26509.     (and the other types for other modules) being redeclared. I
  26510.     had to '#ifndef _AIX' the 'static' modifier.
  26511.  
  26512.   I did manage to fixup md5module.c so the rsademo.py script
  26513. apparently succeeded (only output was "Generating small primes
  26514. list...") on the rs_aix32 machine.
  26515.  
  26516.  
  26517. comments welcomed,
  26518. michael
  26519. 
  26520. 
  26521. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  26522.     id AA08855 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 16:18:43 +0100
  26523. Received: by voorn.cwi.nl with SMTP
  26524.     id AA17506 (5.65b/3.8/CWI-Amsterdam); Thu, 28 Oct 1993 16:18:43 +0100
  26525. Message-Id: <9310281518.AA17506=guido@voorn.cwi.nl>
  26526. To: michael shiplett <michael.shiplett@umich.edu>
  26527. Cc: python-list@cwi.nl
  26528. Subject: Re: md5 module 
  26529. In-Reply-To: Your message of "Thu, 28 Oct 1993 11:07:26 MET."
  26530.              <9310281507.AA10763@totalrecall.rs.itd.umich.edu> 
  26531. From: Guido.van.Rossum@cwi.nl
  26532. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  26533. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  26534. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  26535. Date: Thu, 28 Oct 1993 16:18:43 +0100
  26536. Sender: Guido.van.Rossum@cwi.nl
  26537.  
  26538. > [Michael Shipless complains about the md5 module]
  26539.  
  26540. All I can say to my defense is that I didn't write the md5 module.
  26541. Maybe it worked once and now the interface has subtly changed?
  26542.  
  26543. Anyway, in the next release I'll fix the bugs, change the reference to
  26544. RFC 1321, and include the md5c.c from the RFC in the src directory.
  26545. How does this sound?
  26546.  
  26547. >   I did manage to fixup md5module.c so the rsademo.py script
  26548. > apparently succeeded (only output was "Generating small primes
  26549. > list...") on the rs_aix32 machine.
  26550.  
  26551. That is indeed the only output to be expected.  This script is mostly
  26552. intended to be read (it is about the only documentation on the rsa
  26553. interface...), not to be executed.
  26554.  
  26555. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  26556. 
  26557. 
  26558. Replied: Fri, 29 Oct 1993 11:43:16 +0100
  26559. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> Bill Janssen <janssen@parc.xerox.com>, python-list@cwi.nl"
  26560. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  26561.     id AA09278 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 16:41:27 +0100
  26562. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa26673;
  26563.           28 Oct 93 11:41 EDT
  26564. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  26565.     id AA14219; Thu, 28 Oct 1993 11:41:03 -0400
  26566. Date: Thu, 28 Oct 1993 11:41:03 -0400
  26567. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  26568. Message-Id: <199310281541.AA14219@elvis.med.Virginia.EDU>
  26569. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  26570. To: Bill Janssen <janssen@parc.xerox.com>, python-list@cwi.nl
  26571. Subject: Re: obtaining the reversal of a sequence?
  26572.  
  26573. While elvis.med.virginia.edu was getting it's disks scrubbed and
  26574. cleaned, I missed the original question that started the thread 
  26575. about range and reverse. 
  26576.  
  26577. On Oct 20, 23:27, Bill Janssen wrote:
  26578. > I've encountered the problem where I'd like to have a sequence that is
  26579. > traversed in both directions equally frequently.  It's a display list, and
  26580. > is traversed from back to front, to paint the window, and from front to
  26581. > back, to find the innermost element enclosing a point.
  26582. > Clearly, the ``for foo in x'' construct works well for one of the two
  26583. > cases, but what's the efficient way to traverse the list in reverse order?
  26584. > The best I can come up with is:
  26585. >     tmp = list[:]
  26586. >     tmp.reverse()
  26587. >     for x in tmp:
  26588. >         blah...
  26589. > and that's so inefficient I believe there must be some trick tucked away
  26590. > to make this easier.
  26591. > Bill
  26592. > -- End of excerpt from Bill Janssen <janssen@parc.xerox.com>
  26593.  
  26594.  
  26595. But playing around with pseudo-sequences ( in my prev. posts ) suggests 
  26596. a trick: 
  26597.  
  26598. class Rev:
  26599.         def __init__( self, seq ):
  26600.                 self.forw = seq
  26601.                 self.back = self
  26602.         def __len__( self ):
  26603.                 return len( self.forw )
  26604.         def __getitem__( self, j ):
  26605.                 return self.forw[ -( j + 1 ) ]
  26606.         def __repr__( self ):
  26607.                 return '<reverse of sequence: ' + repr(self.forw) +' >'
  26608.  
  26609.  
  26610. It works on mutable or inmutable sequences.
  26611.  
  26612. >>> for c in Rev( 'Hello World!' ) : sys.stdout.write( c )
  26613. ... else: sys.stdout.write( '\n' )
  26614. ... 
  26615. !dlroW olleH
  26616. >>> 
  26617.  
  26618. The .forw is so you can use anonymous sequences in init, and still
  26619. keep a reference the forward sequence. ) 
  26620. If you give it a non-anonymous mutable sequence, the reverse sequence
  26621. will track the updated values. ( but not reassignment! - another 
  26622. good reason to use anonymous values in creating the sequence to avoid
  26623. confusion. Maybe it should be change to copy input sequence to break
  26624. the connection completely ? )
  26625.  
  26626.  
  26627. >>> nnn = range( 0, 3 )
  26628. >>> rnn = Rev( nnn )
  26629. >>> for n in rnn: print n
  26630. ... 
  26631. 2
  26632. 1
  26633. 0
  26634. >>> for n in range( 4, 6 ): nnn.append( n )    # update nnn
  26635. ... 
  26636. >>> for n in rnn: print n    # prints reversed updated values
  26637. ... 
  26638. 5
  26639. 4
  26640. 2
  26641. 1
  26642. 0
  26643. >>> nnn = nnn[1:-1]
  26644. >>> nnn
  26645. [1, 2, 4]
  26646. >>> for n in rnn: print n    # prints reversed values of old nnn
  26647. ... 
  26648. 5
  26649. 4
  26650. 2
  26651. 1
  26652. 0
  26653. >>> 
  26654.  
  26655.  
  26656. I'll leave it to Guido or someone else to figure out how this
  26657. compares effeciency wise with the other solutions. 
  26658.  
  26659.  
  26660. ToDo's: 
  26661.  repr() ought to return a more natural representation, but then it 
  26662.  has to check for type of argument to know whether to wrap the 
  26663.  reversed values in "[]" or "()" or something else or nothing.  
  26664.  
  26665.  Add more methods to make rseq.back completely comparable to 
  26666.  rseq.forw. e.g. rseq.back.append( ) would insert a value at 
  26667.  the BEGINNING of rseq.forw. , etc. 
  26668.  
  26669.  
  26670. Also note to Terrence Brannon and others who have complained about
  26671. strings being non-mutable: you can probably tell from these various
  26672. pseudo-sequences that it would be pretty easy to make a mutable-string
  26673. class. It isn't something I've felt as a requirement, but since it's 
  26674. so easy, maybe we ought to put one in the standard library. 
  26675.  
  26676. Right now I'm more interested in figuring out a more natural way of
  26677. expressing regular expressions and other non-regexp patterns ( like
  26678. matching parends. ) using operators on character set classes and 
  26679. pattern classes instead of characters with special meanings that may
  26680. or may not have to be escaped. 
  26681. i.e. something like: 
  26682.   Any( letters ) + Any( letters ) * 5 + Any( digits + '_$' ) * 3 
  26683. ( where letters and digits are imported from string, and 'Any' would be
  26684.  a class constructor. )
  26685. translating into regexp: [a-zA-Z][a-zA-A]*5[0-9]*3 
  26686. ( where *5 means 0-5 occurances - a specification feature I've not seen
  26687. in all regexp modules. )
  26688.  
  26689. Any comments on the usefulness of this sort of interface to regexp, or
  26690. the desired syntax or semantics ? 
  26691.  
  26692. - Steve Majewski
  26693.  
  26694. 
  26695. 
  26696. Replied: Fri, 29 Oct 1993 10:46:55 +0100
  26697. Replied: "michael shiplett <michael.shiplett@umich.edu> "
  26698. Received: from totalrecall.rs.itd.umich.edu by charon.cwi.nl with SMTP
  26699.     id AA10798 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 17:42:15 +0100
  26700. Received: from enchanter.ifs.umich.edu by totalrecall.rs.itd.umich.edu (5.67/2.2)
  26701.     with SMTP id AA16029; Thu, 28 Oct 93 12:42:13 -0400
  26702. Message-Id: <9310281642.AA16029@totalrecall.rs.itd.umich.edu>
  26703. To: Guido.van.Rossum@cwi.nl
  26704. Subject: Re: md5 module 
  26705. In-Reply-To: Your message of Thu, 28 Oct 1993 16:18:43 +0100.
  26706.              <9310281518.AA17506=guido@voorn.cwi.nl> 
  26707. From: michael shiplett <michael.shiplett@umich.edu>
  26708. Date: Thu, 28 Oct 1993 12:42:12 -0400
  26709. Sender: walrus@umich.edu
  26710.  
  26711. "gvr" == Guido.van.Rossum  <Guido.van.Rossum@cwi.nl> writes:
  26712.  
  26713. > [Michael Shiplett complains about the md5 module]
  26714.  
  26715. gvr> All I can say to my defense is that I didn't write the md5 module.
  26716. gvr> Maybe it worked once and now the interface has subtly changed?
  26717.  
  26718.   I didn't mean to make it sound like complaining so much as things
  26719. which seemed not quite right. Being new to python, I wasn't sure if it
  26720. was a problem specific to my configuration or the md5 module itself.
  26721. Trying to fix the md5 module, I've learned my way around the rsa.com
  26722. site & even picked up a couple PEM packages, so it's been time well
  26723. spent.
  26724.  
  26725. gvr> Anyway, in the next release I'll fix the bugs, change the reference to
  26726. gvr> RFC 1321, and include the md5c.c from the RFC in the src directory.
  26727. gvr> How does this sound?
  26728.  
  26729.   Looking at the copyright notice, I think including the RFC files is
  26730. okay, provided your docs identify the software as the "RSA Data
  26731. Security, Inc. MD5 Message-Digest Algorithm." The files global.h
  26732. (rename to md5global.h???) & md5.h should be included as well.
  26733. Bundling all the md5 support package seems like a good thing to me.
  26734.  
  26735.   Have there been any other comments about the extern declarations of
  26736. static functions causing problems for linkers? I haven't tested them
  26737. on the NeXT yet.
  26738.  
  26739.   In case you're interested, I've appended my changes for the md5
  26740. module.
  26741.  
  26742.   Now all I need is some time to learn how to use python :)
  26743.  
  26744. thanks for the rapid feedback,
  26745. michael
  26746.  
  26747.  
  26748.  
  26749. *** md5module.distrib    Thu Oct 28 08:34:30 1993
  26750. --- md5module.c    Thu Oct 28 12:29:17 1993
  26751. ***************
  26752. *** 31,36 ****
  26753. --- 31,37 ----
  26754.   #include "allobjects.h"
  26755.   #include "modsupport.h"        /* For getargs() etc. */
  26756.   
  26757. + #include "global.h"        /* UINT4 */
  26758.   #include "md5.h"
  26759.   typedef struct {
  26760.       OB_HEAD
  26761. ***************
  26762. *** 128,150 ****
  26763.       return None;
  26764.   } /* md5_update() */
  26765.   
  26766.   static object *
  26767.   md5_digest(self, args)
  26768.       md5object *self;
  26769.       object *args;
  26770.   {
  26771.       MD5_CTX mdContext;
  26772. !     stringobject *strobjp;
  26773.   
  26774.       if (!getnoarg(args))
  26775.           return NULL;
  26776.   
  26777.       /* make a temporary copy, and perform the final */
  26778.       mdContext = self->md5;
  26779. !     MD5Final(&mdContext);
  26780.   
  26781. !     return newsizedstringobject((char *)mdContext.digest, 16);
  26782.   } /* md5_digest() */
  26783.   
  26784.   static object *
  26785.   md5_copy(self, args)
  26786. --- 129,155 ----
  26787.       return None;
  26788.   } /* md5_update() */
  26789.   
  26790. + #define DIGESTLEN    16    /* this is used twice--walrus@umich.edu */
  26791.   static object *
  26792.   md5_digest(self, args)
  26793.       md5object *self;
  26794.       object *args;
  26795.   {
  26796.       MD5_CTX mdContext;
  26797. !     char aDigest[DIGESTLEN];
  26798. !     
  26799.   
  26800.       if (!getnoarg(args))
  26801.           return NULL;
  26802.   
  26803.       /* make a temporary copy, and perform the final */
  26804.       mdContext = self->md5;
  26805. !     MD5Final(aDigest, &mdContext);
  26806.   
  26807. !     return newsizedstringobject((char *)aDigest, DIGESTLEN);
  26808.   } /* md5_digest() */
  26809. + #undef DIGESTLEN
  26810.   
  26811.   static object *
  26812.   md5_copy(self, args)
  26813. ***************
  26814. *** 181,188 ****
  26815.       return findmethod(md5_methods, (object *)self, name);
  26816.   } /* md5_getattr() */
  26817.   
  26818. ! static typeobject MD5type = {
  26819.       OB_HEAD_INIT(&Typetype)
  26820.       0,            /*ob_size*/
  26821.       "md5",            /*tp_name*/
  26822. --- 186,195 ----
  26823.       return findmethod(md5_methods, (object *)self, name);
  26824.   } /* md5_getattr() */
  26825.   
  26826. ! #ifndef _AIX
  26827. ! static
  26828. ! #endif
  26829. ! typeobject MD5type = {
  26830.       OB_HEAD_INIT(&Typetype)
  26831.       0,            /*ob_size*/
  26832.       "md5",            /*tp_name*/
  26833. 
  26834. 
  26835. Replied: Fri, 29 Oct 1993 11:20:59 +0100
  26836. Replied: ""Steven D. Majewski" <sdm7g@galen.med.virginia.edu> python-list@cwi.nl"
  26837. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  26838.     id AA11271 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 18:02:13 +0100
  26839. Received: from galen.med.virginia.edu by uvaarpa.virginia.edu id aa12226;
  26840.           28 Oct 93 13:02 EDT
  26841. Received: by galen.med.Virginia.EDU (5.67a8/1.34)
  26842.     id AA22753; Thu, 28 Oct 1993 13:02:08 -0400
  26843. Date: Thu, 28 Oct 1993 13:02:08 -0400
  26844. From: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  26845. Message-Id: <199310281702.AA22753@galen.med.Virginia.EDU>
  26846. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  26847. To: python-list@cwi.nl
  26848. Subject: Rev() with better repr [and complaint about pedantic typechecking]
  26849.  
  26850.  
  26851. Here's Rev() with a better __repr__() method.
  26852.  
  26853. WH = Rev( 'Hello World!' )
  26854. print WH.forw, WH.back
  26855. nnn = Rev( range( 1, 10 ) )
  26856. print nnn.forw
  26857. print nnn
  26858.  
  26859. produces output:
  26860.  
  26861. Hello World! !dlroW olleH
  26862. [1, 2, 3, 4, 5, 6, 7, 8, 9]
  26863. [9, 8, 7, 6, 5, 4, 3, 2, 1]
  26864.  
  26865. >>>rrr = Rev( nnn ) 
  26866. >>>rrr
  26867. <1, 2, 3, 4, 5, 6, 7, 8, 9>    
  26868.  
  26869. # NOT [1, 2, ... 9]  i.e. it doesn't check:
  26870. if type(self) == type( Rev([]) ) && self.__class__ == Rev( [] ).__class__ 
  26871. but THAT belongs to an OLD thread... 
  26872.  
  26873. WHICH brings up the need for building a list of values for joinfields
  26874. which doen't work on a pseudo sequence object:
  26875.  
  26876. >>>joinfields( Rev( string.split( 'This is a test' )), ':::' ) 
  26877. Stack backtrace (innermost last):
  26878.   File "<stdin>", line 1
  26879. TypeError: first argument must be list/tuple
  26880.  
  26881. Unnecessarily pedantic typechecking ? 
  26882.  
  26883. Not in string.py (as far as I can tell). It must be from the internal
  26884. strop version. Is there any way to import the joinfields from 
  26885. string.py over the one in strop module ? ( Or is the solution 
  26886. to fix strop's joinfields ? ) 
  26887.  
  26888. Needs and __add__ method before you can "print WH.forw + WH.back". 
  26889.  
  26890.  
  26891. - Steve 
  26892.  
  26893.  
  26894. #-----------
  26895. from string import joinfields
  26896. class Rev:
  26897.     def __init__( self, seq ):
  26898.         self.forw = seq
  26899.         self.back = self
  26900.     def __len__( self ):
  26901.         return len( self.forw )
  26902.     def __getitem__( self, j ):
  26903.         return self.forw[ -( j + 1 ) ]
  26904.     def __repr__( self ):
  26905.         seq = self.forw
  26906.         if type(seq) == type( [] ) : 
  26907.             wrap = '[]'
  26908.             sep = ', '
  26909.         elif type(seq) == type( () ) : 
  26910.             wrap = '()'
  26911.             sep = ', '
  26912.         elif type(seq) == type( '' ) : 
  26913.             wrap = ''
  26914.             sep = ''
  26915.         else: 
  26916.             wrap = '<>'
  26917.             sep = ', ' 
  26918.         outstrs = []
  26919.         for item in self.back :
  26920.             outstrs.append( str( item ) )
  26921.         return wrap[:1] + joinfields( outstrs, sep ) + wrap[-1:]
  26922.  
  26923.  
  26924.  
  26925. 
  26926. 
  26927. Replied: Fri, 29 Oct 1993 11:31:58 +0100
  26928. Replied: ""Steven D. Majewski" <sdm7g@galen.med.virginia.edu> "
  26929. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  26930.     id AA14596 (5.65b/3.11/CWI-Amsterdam); Thu, 28 Oct 1993 22:40:43 +0100
  26931. Received: from galen.med.virginia.edu by uvaarpa.virginia.edu id aa26401;
  26932.           28 Oct 93 17:40 EDT
  26933. Received: by galen.med.Virginia.EDU (5.67a8/1.34)
  26934.     id AA35634; Thu, 28 Oct 1993 17:40:32 -0400
  26935. Date: Thu, 28 Oct 1993 17:40:32 -0400
  26936. From: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  26937. Message-Id: <199310282140.AA35634@galen.med.Virginia.EDU>
  26938. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  26939. To: python-list@cwi.nl
  26940. Subject: Re: Rev() with better repr [and complaint about pedantic typechecking]
  26941.  
  26942.  
  26943. I wrote ( re: difference in string.joinfields vs. strop.joinfields )
  26944. > Not in string.py (as far as I can tell). It must be from the internal
  26945. > strop version. Is there any way to import the joinfields from 
  26946. > string.py over the one in strop module ? ( Or is the solution 
  26947. > to fix strop's joinfields ? ) 
  26948.  
  26949. I didn't actually mean that question the way it was phrased.
  26950. [ Well - yes, I *DID* mean it at the time, but I wasn't thinking! :-) ]
  26951. There's a clear way HOW to import string.joinfields 
  26952. rather than strop.joinfields: either edit the "try: from strop import *"
  26953. line out of strings.py, or copy join & joinfields in another file
  26954. ( join.py ). 
  26955.  
  26956. What I really meant was: 
  26957.  (1) does anyone else besides me really CARE that they don't work 
  26958.      identically? 
  26959.  (2) and is the "correct & standard" fix to distinguish the two 
  26960.      more clearly ( a "generic" join and a _s_t_r_i_n_g_.join[fields],
  26961.      or to make strop.join[fields] work like string.join[fields] ? 
  26962.  
  26963. It wouldn't work generically for what I wanted to do with repr,
  26964. since I didn't want to join the values but the repr's of the values.
  26965.  
  26966. But it WOULD be nice if string and sequence functions worked for
  26967. pseudo-strings and pseudo-sequence object classes. For example -
  26968. if I actually wrote a mutable string class, I would expect 
  26969. string.split to work on it. ( strop.split won't. )
  26970.  
  26971.  
  26972. Finally: 
  26973.  Maybe a better repr for Rev is: 
  26974.   Rev( repr( Rev( seq ).forw ) )
  26975.  i.e. just the reverse of the string-representation of the sequence:
  26976.  
  26977. >>> Rev( repr( Rev( [1,2,3] ).forw ) )
  26978. ]3 ,2 ,1[
  26979. >>> Rev( repr( Rev( (1,2,3) ).forw ) )
  26980. )3 ,2 ,1(
  26981. >>> Rev( repr( Rev( '123' ).forw ) )
  26982. '321'
  26983. >>> 
  26984.  
  26985. Looks a little strange, but it indicates, for tuples and lists,
  26986. that they really *aren't* tuples or lists. 
  26987.  
  26988. - Steve Majewski
  26989.  
  26990. 
  26991. 
  26992. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  26993.     id AA23402 (5.65b/3.11/CWI-Amsterdam); Fri, 29 Oct 1993 11:21:00 +0100
  26994. Received: by voorn.cwi.nl with SMTP
  26995.     id AA19226 (5.65b/3.8/CWI-Amsterdam); Fri, 29 Oct 1993 11:20:59 +0100
  26996. Message-Id: <9310291020.AA19226=guido@voorn.cwi.nl>
  26997. To: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  26998. Cc: python-list@cwi.nl
  26999. Subject: Re: Rev() with better repr [and complaint about pedantic typechecking] 
  27000. In-Reply-To: Your message of "Thu, 28 Oct 1993 13:02:08 MET."
  27001.              <199310281702.AA22753@galen.med.Virginia.EDU> 
  27002. From: Guido.van.Rossum@cwi.nl
  27003. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27004. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27005. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27006. Date: Fri, 29 Oct 1993 11:20:59 +0100
  27007. Sender: Guido.van.Rossum@cwi.nl
  27008.  
  27009. > WHICH brings up the need for building a list of values for joinfields
  27010. > which doen't work on a pseudo sequence object:
  27011. > >>>joinfields( Rev( string.split( 'This is a test' )), ':::' ) 
  27012. > Stack backtrace (innermost last):
  27013. >   File "<stdin>", line 1
  27014. > TypeError: first argument must be list/tuple
  27015. > Unnecessarily pedantic typechecking ? 
  27016. > Not in string.py (as far as I can tell). It must be from the internal
  27017. > strop version. Is there any way to import the joinfields from 
  27018. > string.py over the one in strop module ? ( Or is the solution 
  27019. > to fix strop's joinfields ? ) 
  27020.  
  27021. strop.joinfields should be fixed (and it appears not too difficult).
  27022. If you don't want the strop version, you'll have to copy string.py to
  27023. string_in_python.py, take the strop reference out, and use that...
  27024.  
  27025. However, note that in general updating all built-in functions that
  27026. currently only take lists and/or tuples as arguments might prove a
  27027. major undertaking...  There is much more to check and the reference
  27028. count handling is different...  Some time...  When I retire...
  27029.  
  27030. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27031. 
  27032. 
  27033. To: "Steven D. Majewski" <sdm7g@galen.med.virginia.edu>
  27034. Subject: Re: Rev() with better repr [and complaint about pedantic typechecking] 
  27035. In-reply-to: Your message of "Thu, 28 Oct 1993 17:40:32 MET."
  27036.              <199310282140.AA35634@galen.med.Virginia.EDU> 
  27037. From: Guido.van.Rossum@cwi.nl
  27038. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27039. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27040. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27041. Date: Fri, 29 Oct 1993 11:31:58 +0100
  27042. Sender: guido
  27043.  
  27044. > But it WOULD be nice if string and sequence functions worked for
  27045. > pseudo-strings and pseudo-sequence object classes. For example -
  27046. > if I actually wrote a mutable string class, I would expect 
  27047. > string.split to work on it. ( strop.split won't. )
  27048.  
  27049. Well it is possible in most cases to write Python code to work
  27050. irrespective of the actual sequence type used.  It takes a little
  27051. care, e.g. you must use a[:0] (where a is the argument of unknown
  27052. sequence type) instead of an empty value of a specific type.
  27053.  
  27054. I don't know if all the code in string.py is correct in this respect;
  27055. I suspect not, but most of it will be okay -- on the other hand it is
  27056. only intended to work on strings so who cares.  I suppose an
  27057. appropriate subset of the routines from string.py could be provided as
  27058. sequence.py (totally avoiding the "from strop import *" issue).
  27059.  
  27060. On the other hand, as I wrote in my previous mail, fixing strop and
  27061. other built-in modules to have the same kind of genericity would be
  27062. difficult.  Strop was designed to implement string manipulations as
  27063. fast as possible by exploiting the C representation; perhaps a seqop
  27064. module could be written which does somilar things for generic
  27065. sequences.
  27066.  
  27067. Any volunteers?
  27068.  
  27069. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27070. 
  27071. 
  27072. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27073.     id AA23746 (5.65b/3.11/CWI-Amsterdam); Fri, 29 Oct 1993 11:43:17 +0100
  27074. Received: by voorn.cwi.nl with SMTP
  27075.     id AA19339 (5.65b/3.8/CWI-Amsterdam); Fri, 29 Oct 1993 11:43:17 +0100
  27076. Message-Id: <9310291043.AA19339=guido@voorn.cwi.nl>
  27077. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27078. Cc: Bill Janssen <janssen@parc.xerox.com>, python-list@cwi.nl
  27079. Subject: Re: obtaining the reversal of a sequence? 
  27080. In-Reply-To: Your message of "Thu, 28 Oct 1993 11:41:03 MET."
  27081.              <199310281541.AA14219@elvis.med.Virginia.EDU> 
  27082. From: Guido.van.Rossum@cwi.nl
  27083. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27084. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27085. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27086. Date: Fri, 29 Oct 1993 11:43:16 +0100
  27087. Sender: Guido.van.Rossum@cwi.nl
  27088.  
  27089. If speed is what you need, and you need to traverse a list backwards,
  27090. there is no way (without resorting to C) to beat
  27091.  
  27092.     list.reverse()
  27093.     try:
  27094.         for item in list: ...
  27095.     finally:
  27096.         list.reverse()
  27097.  
  27098. A close second which leaves the forward value of list accessible is
  27099.  
  27100.     rev = list[:]
  27101.     rev.reverse()
  27102.     for item in rev: ...
  27103.  
  27104. Anything that involves maintaining the loop index in a Python variable
  27105. is much slower.  I personally wouldn't worry about the space overhead
  27106. of the second solution, but some people might.  My feeling is that by
  27107. the time you have a list that's so long that a second copy of the
  27108. *list* (not its items!) is a problem, *doing* anything with all of its
  27109. items in a for loop will take forever -- unless you have a totally
  27110. memory starved machine with a race horse of a CPU...
  27111.  
  27112. > Also note to Terrence Brannon and others who have complained about
  27113. > strings being non-mutable: you can probably tell from these various
  27114. > pseudo-sequences that it would be pretty easy to make a mutable-string
  27115. > class. It isn't something I've felt as a requirement, but since it's 
  27116. > so easy, maybe we ought to put one in the standard library. 
  27117.  
  27118. There is already something like this: the built-in array module (which
  27119. is currently optional but should be part of every Python interpreter
  27120. nevertheless).  array.array('c') creates an empty array of characters
  27121. which supports list-like operations (including append & insert).  The
  27122. only drawback is that array objects aren't acceptable to built-in
  27123. functions requiring a string, and e.g. file.read() doesn't return an
  27124. array so you would have to copy it (e.g. using array.array('c',
  27125. file.read()).
  27126.  
  27127. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27128. 
  27129. 
  27130. Replied: Sat, 30 Oct 1993 01:28:55 +0100
  27131. Replied: "Bill Janssen <janssen@parc.xerox.com> python-list@cwi.nl"
  27132. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  27133.     id AA02675 (5.65b/3.11/CWI-Amsterdam); Fri, 29 Oct 1993 22:07:27 +0100
  27134. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11994(2)>; Fri, 29 Oct 1993 14:07:02 PDT
  27135. Received: by holmes.parc.xerox.com id <16134>; Fri, 29 Oct 1993 14:06:53 -0700
  27136. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  27137.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  27138.           Fri, 29 Oct 1993 14:06:42 -0700 (PDT)
  27139. Message-Id: <ggoMLWUB0KGW42rKQi@holmes.parc.xerox.com>
  27140. Date:     Fri, 29 Oct 1993 14:06:42 PDT
  27141. Sender: Bill Janssen <janssen@parc.xerox.com>
  27142. From: Bill Janssen <janssen@parc.xerox.com>
  27143. To: python-list@cwi.nl
  27144. Subject: recursive internal function
  27145.  
  27146. Next question:  how do I write something like the function foo():
  27147.  
  27148. def bar (x):
  27149.  
  27150.     def foo (y):
  27151.  
  27152.         if (y > 100): return
  27153.         ... do something with y...
  27154.         foo (y*2)
  27155.  
  27156.     ... do something with x...
  27157.     foo(x*3)
  27158.  
  27159. bar(1)
  27160.  
  27161. I suppose I just can't.
  27162.  
  27163. Bill
  27164. 
  27165. 
  27166. To: Bill Janssen <janssen@parc.xerox.com>
  27167. cc: python-list@cwi.nl
  27168. Subject: Re: recursive internal function 
  27169. In-reply-to: Your message of "Fri, 29 Oct 1993 14:06:42 MDT."
  27170.              <ggoMLWUB0KGW42rKQi@holmes.parc.xerox.com> 
  27171. From: Guido.van.Rossum@cwi.nl
  27172. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27173. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27174. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27175. Date: Sat, 30 Oct 1993 01:28:55 +0100
  27176. Sender: guido
  27177.  
  27178. > Next question:  how do I write something like the function foo():
  27179. > def bar (x):
  27180. >     def foo (y):
  27181. >         if (y > 100): return
  27182. >         ... do something with y...
  27183. >         foo (y*2)
  27184. >     ... do something with x...
  27185. >     foo(x*3)
  27186. > bar(1)
  27187. > I suppose I just can't.
  27188.  
  27189. Well...  You could add "global foo" before the "def foo...", but I
  27190. suppose it would defeat the purpose of making foo a local function.
  27191.  
  27192. Alternatively, you could define and instantiate a local class with a
  27193. recursive method foo().  But by the time you're doing that, you may be
  27194. better off structuring your whole program as a class instead of as a
  27195. module with functions...
  27196.  
  27197. The moral of this story?  You can trade globals for classes.  Or
  27198. perhaps: don't try to write Pascal in Python ;-)
  27199.  
  27200. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27201. 
  27202. 
  27203. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27204.     id AA04458 (5.65b/3.11/CWI-Amsterdam); Sat, 30 Oct 1993 01:28:56 +0100
  27205. Received: by voorn.cwi.nl with SMTP
  27206.     id AA21487 (5.65b/3.8/CWI-Amsterdam); Sat, 30 Oct 1993 01:28:55 +0100
  27207. Message-Id: <9310300028.AA21487=guido@voorn.cwi.nl>
  27208. To: Bill Janssen <janssen@parc.xerox.com>
  27209. Cc: python-list@cwi.nl
  27210. Subject: Re: recursive internal function 
  27211. In-Reply-To: Your message of "Fri, 29 Oct 1993 14:06:42 MDT."
  27212.              <ggoMLWUB0KGW42rKQi@holmes.parc.xerox.com> 
  27213. From: Guido.van.Rossum@cwi.nl
  27214. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27215. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27216. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27217. Date: Sat, 30 Oct 1993 01:28:55 +0100
  27218. Sender: Guido.van.Rossum@cwi.nl
  27219.  
  27220. > Next question:  how do I write something like the function foo():
  27221. > def bar (x):
  27222. >     def foo (y):
  27223. >         if (y > 100): return
  27224. >         ... do something with y...
  27225. >         foo (y*2)
  27226. >     ... do something with x...
  27227. >     foo(x*3)
  27228. > bar(1)
  27229. > I suppose I just can't.
  27230.  
  27231. Well...  You could add "global foo" before the "def foo...", but I
  27232. suppose it would defeat the purpose of making foo a local function.
  27233.  
  27234. Alternatively, you could define and instantiate a local class with a
  27235. recursive method foo().  But by the time you're doing that, you may be
  27236. better off structuring your whole program as a class instead of as a
  27237. module with functions...
  27238.  
  27239. The moral of this story?  You can trade globals for classes.  Or
  27240. perhaps: don't try to write Pascal in Python ;-)
  27241.  
  27242. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27243. 
  27244. 
  27245. Replied: Wed, 03 Nov 1993 10:45:54 +0100
  27246. Replied: "Mats.Lidell@eua.ericsson.se (Mats Lidell) python-list@cwi.nl"
  27247. Received: from mailgate.ericsson.se by charon.cwi.nl with SMTP
  27248.     id AA10767 (5.65b/%I%/CWI-Amsterdam); Wed, 3 Nov 1993 08:42:04 +0100
  27249. Received: from eua.ericsson.se by mailgate.ericsson.se (4.1/SMI-4.1-MAILGATE1.14)
  27250.     id AA29012; Wed, 3 Nov 93 08:42:00 +0100
  27251. Received: from ms.eua.ericsson.se by eua.ericsson.se (4.1/EUA-2.1)
  27252.     id AA21893; Wed, 3 Nov 93 08:41:58 +0100
  27253. Received: from euas09c18.eua.ericsson.se by ms.eua.ericsson.se (4.1/MS-2.1)
  27254.     id AA22812; Wed, 3 Nov 93 08:41:55 +0100
  27255. From: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  27256. Received: by euas09c18.eua.ericsson.se (4.1/client-1.3)
  27257.     id AA03493; Wed, 3 Nov 93 08:41:54 +0100
  27258. Date: Wed, 3 Nov 93 08:41:54 +0100
  27259. Message-Id: <9311030741.AA03493@euas09c18.eua.ericsson.se>
  27260. To: python-list@cwi.nl
  27261. Subject: Reading binary data from a file.
  27262. Comments: Hyperbole mail buttons accepted, v3.09.
  27263.  
  27264. Hi Folks,
  27265.  
  27266. Just found myself wanting to do this:
  27267.  
  27268.     Integer = f.read(4)
  27269.  
  27270. Yes. I have an integer (in binary) on a file and I know that my
  27271. machine representation of this interger is 4 bytes. So I want to read
  27272. these 4 bytes and convert them into a python integer. Is there some
  27273. support for this or do I have to do a conversion function?
  27274.  
  27275. %% Mats
  27276. 
  27277. 
  27278. Replied: Wed, 03 Nov 1993 10:26:48 +0100
  27279. Replied: "Mats.Lidell@eua.ericsson.se (Mats Lidell) Python Mailing List <python-list@cwi.nl>"
  27280. Received: from mailgate.ericsson.se by charon.cwi.nl with SMTP
  27281.     id AA11496 (5.65b/%I%/CWI-Amsterdam); Wed, 3 Nov 1993 09:48:52 +0100
  27282. Received: from eua.ericsson.se by mailgate.ericsson.se (4.1/SMI-4.1-MAILGATE1.14)
  27283.     id AA01229; Wed, 3 Nov 93 09:48:44 +0100
  27284. Received: from ms.eua.ericsson.se by eua.ericsson.se (4.1/EUA-2.1)
  27285.     id AA24345; Wed, 3 Nov 93 09:48:43 +0100
  27286. Received: from euas09c18.eua.ericsson.se by ms.eua.ericsson.se (4.1/MS-2.1)
  27287.     id AA02543; Wed, 3 Nov 93 09:48:42 +0100
  27288. From: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  27289. Received: by euas09c18.eua.ericsson.se (4.1/client-1.3)
  27290.     id AA04289; Wed, 3 Nov 93 09:48:41 +0100
  27291. Date: Wed, 3 Nov 93 09:48:41 +0100
  27292. Message-Id: <9311030848.AA04289@euas09c18.eua.ericsson.se>
  27293. To: Python Mailing List <python-list@cwi.nl>
  27294. Subject: Variable arguments in modules
  27295. Comments: Hyperbole mail buttons accepted, v3.09.
  27296.  
  27297. Hi Folks,
  27298.  
  27299. A variable number of arguments to a C-function isn't that unusual. (At
  27300. least I have a C-library that I would like to interface to python that
  27301. has a lot of functions that take variable number of arguments.)
  27302. Unfortunately it seems like the support for extension modules written
  27303. in C currently doesn't support this. Right?
  27304.  
  27305. I guess I can always write a C-layer with fixed number argument
  27306. functions that concatenates the arguments and a corresponding python
  27307. wrapper but that seems a bit silly.
  27308.  
  27309.  Q1: Is there some neat way to do this that I'm missing?
  27310.  
  27311.  Q2: Any experiences from the list with this problem would be
  27312.      appreciated? (source ;-)
  27313.  
  27314. %% Mats
  27315. 
  27316. 
  27317. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27318.     id AA12051 (5.65b/%I%/CWI-Amsterdam); Wed, 3 Nov 1993 10:26:49 +0100
  27319. Received: by voorn.cwi.nl with SMTP
  27320.     id AA02821 (5.65b/3.8/CWI-Amsterdam); Wed, 3 Nov 1993 10:26:49 +0100
  27321. Message-Id: <9311030926.AA02821=guido@voorn.cwi.nl>
  27322. To: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  27323. Cc: Python Mailing List <python-list@cwi.nl>
  27324. Subject: Re: Variable arguments in modules 
  27325. In-Reply-To: Your message of "Wed, 03 Nov 1993 09:48:41 MET."
  27326.              <9311030848.AA04289@euas09c18.eua.ericsson.se> 
  27327. From: Guido.van.Rossum@cwi.nl
  27328. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27329. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27330. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27331. Date: Wed, 03 Nov 1993 10:26:48 +0100
  27332. Sender: Guido.van.Rossum@cwi.nl
  27333.  
  27334. > A variable number of arguments to a C-function isn't that unusual. (At
  27335. > least I have a C-library that I would like to interface to python that
  27336. > has a lot of functions that take variable number of arguments.)
  27337. > Unfortunately it seems like the support for extension modules written
  27338. > in C currently doesn't support this. Right?
  27339.  
  27340. I assume you're thinking of making a Python wrapper for a
  27341. printf()-like function?
  27342.  
  27343. The problem here is that C doesn't support this in a portable general
  27344. manner (in fact that's why vprintf() et al. were invented).  There is
  27345. no way to "break open" the calling sequence.  (I.e. C doesn't have an
  27346. equivalent to Python's "apply()".)
  27347.  
  27348. > I guess I can always write a C-layer with fixed number argument
  27349. > functions that concatenates the arguments and a corresponding python
  27350. > wrapper but that seems a bit silly.
  27351.  
  27352. Yes I guess the closest you can get is something like
  27353.  
  27354.     switch (gettuplesize(args)) {
  27355.     case 0: foo(); break;
  27356.     case 1: foo(getintvalue(gettupleitem(args, 0)),
  27357.             getintvalue(gettupleitem(args, 1))); break;
  27358.     /* etc. */
  27359.     }
  27360.  
  27361. This assumes that all arguments are of a fixed type (i.e. printf()
  27362. would still be impossible to do right protably, since there are
  27363. compilers that pass floats or doubles in a different way than ints).
  27364.  
  27365. Note that you can set the third element of the "struct methodlist" to
  27366. 1 to indicate that the Python argument list should always be passed as
  27367. a tuple, instead of passing NULL for no arguments and the argument
  27368. itself for one argument as is the default.
  27369.  
  27370. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27371. 
  27372. 
  27373. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27374.     id AA12364 (5.65b/%I%/CWI-Amsterdam); Wed, 3 Nov 1993 10:45:56 +0100
  27375. Received: by voorn.cwi.nl with SMTP
  27376.     id AA02905 (5.65b/3.8/CWI-Amsterdam); Wed, 3 Nov 1993 10:45:55 +0100
  27377. Message-Id: <9311030945.AA02905=guido@voorn.cwi.nl>
  27378. To: Mats.Lidell@eua.ericsson.se (Mats Lidell)
  27379. Cc: python-list@cwi.nl
  27380. Subject: Re: Reading binary data from a file. 
  27381. In-Reply-To: Your message of "Wed, 03 Nov 1993 08:41:54 MET."
  27382.              <9311030741.AA03493@euas09c18.eua.ericsson.se> 
  27383. From: Guido.van.Rossum@cwi.nl
  27384. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27385. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27386. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27387. Date: Wed, 03 Nov 1993 10:45:55 +0100
  27388. Sender: Guido.van.Rossum@cwi.nl
  27389.  
  27390. > Just found myself wanting to do this:
  27391. >     Integer = f.read(4)
  27392. > Yes. I have an integer (in binary) on a file and I know that my
  27393. > machine representation of this interger is 4 bytes. So I want to read
  27394. > these 4 bytes and convert them into a python integer. Is there some
  27395. > support for this or do I have to do a conversion function?
  27396.  
  27397. Two possible ways, using different (optional, but highly recommended)
  27398. built-in modules:
  27399.  
  27400.  
  27401. (1) Using module struct, you can convert almost any binary data (in
  27402. your host's format and byte order) to Python.  In this case it would
  27403. be:
  27404.  
  27405.     import struct
  27406.     (Integer,) = struct.unpack('l', f.read(4))
  27407.  
  27408. This is the appropriate method if you are reading something like a
  27409. header structure; the format string can specify a list of types
  27410. describing the header, e.g. 'hhl' would be two shorts and a long,
  27411. converted to a triple of three Python integers.
  27412.  
  27413. Notes:
  27414.  
  27415. (a) struct.unpack() always returns a tuple, hence the funny left-hand
  27416. side of the assignment
  27417.  
  27418. (b) the choice of a format letter is machine dependent -- 'l' is a
  27419. machine 'long' (usually 4 bytes but can be 8 e.g. on DEC alpha or HP
  27420. snake); 'i' is a machine 'int' (usually 4 bytes but can be 2 e.g. on
  27421. Mac or PC)
  27422.  
  27423. (c) there is currently no way to specify an alternate byte order
  27424.  
  27425.  
  27426. (2) Using module array, you can efficiently read arrays of simple data
  27427. types:
  27428.  
  27429.     import array
  27430.     a = array.array('l')
  27431.     a.read(f, 1)
  27432.     Integer = a[0]
  27433.  
  27434. This is the appropriate method if you want to read many items of the
  27435. same type, e.g. to read a 1000 integers in one fell swoop, you would
  27436. use a.read(f, 1000).  The same remark about the choice of format
  27437. letter applies; but there is a method to byte swap an entire array
  27438. (a.byteswap()) -- currently undocumented.
  27439.  
  27440. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27441.  
  27442. 
  27443. 
  27444. Replied: Thu, 04 Nov 1993 11:22:05 +0100
  27445. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> python-list"
  27446. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  27447.     id AA21170 (5.65b/%I%/CWI-Amsterdam); Wed, 3 Nov 1993 18:28:50 +0100
  27448. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa12804;
  27449.           3 Nov 93 12:28 EST
  27450. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  27451.     id AA19031; Wed, 3 Nov 1993 12:28:35 -0500
  27452. Date: Wed, 3 Nov 1993 12:28:35 -0500
  27453. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27454. Message-Id: <199311031728.AA19031@elvis.med.Virginia.EDU>
  27455. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  27456. To: python-list@cwi.nl
  27457. Subject: str() and repr() of sequence like classes, esp. 'array' [RFC]
  27458.  
  27459.  
  27460. I was suprised when I first tried using the array module and 
  27461. when I typed:
  27462.  
  27463.     >>>array( 'f' )
  27464.  
  27465. I got back:
  27466.  
  27467.     array( 'f' )
  27468.  
  27469. Not what I was *expecting* to see.
  27470.  
  27471. My puzzlement faded when I next typed:
  27472.  
  27473.     >>>array( 'f', [ 1,2,3,4,5 ] )
  27474.  
  27475. and got:
  27476.  
  27477.     array('f', [1.0, 2.0, 3.0, 4.0, 5.0])
  27478.  
  27479.  
  27480. Neat!
  27481. The print representation is able to reproduce the object:
  27482.  
  27483. >>> ( eval(str(array('f',[1,2,3,4,5]))) == array('f',[1,2,3,4,5]) )
  27484. 1
  27485.  
  27486.  
  27487. An admirable goal.
  27488.  
  27489. However - In some of the example sequence-like classes I have thrown
  27490. together, I have tended towards trying to make the new classes behave
  27491. generally like the objects they are trying to replace. 
  27492. Well - except for that ") (" , "] [" business for reverse sequences. 
  27493. Maybe I haven't been consistant with that rule, but I've played 
  27494. around with the technique enough to see that it, also is a useful
  27495. feature. And even there, though I was willing to accept ') 3 ,2 ,1 (' 
  27496. as the reverse of '( 1,2,3 )', I was trying at the same time to 
  27497. get "Hello World!" to be "!dlroW olloH" .  - I think I was starting
  27498. to graple with the "correct" way to distinguish the behaviour of 
  27499. str() and repr().  [ And 'array' brings up some of the same questions.]
  27500.  
  27501.  
  27502. If a mutable string is going to be "drop replacable"  in a lot of
  27503. proceures that expect a string, then :
  27504.  
  27505.     >>>print mutable-string-obj 
  27506.  
  27507. ought to do pretty much the same thing as:
  27508.  
  27509.     >>>print string
  27510.  
  27511. With 'array', I have to say:
  27512.  
  27513.     >>> print array( 'c' , 'Hello World!' ).tostring()
  27514.     Hello World!
  27515.  
  27516. because:
  27517.  
  27518.     >>> print array( 'c' , 'Hello World!' )
  27519.  
  27520. gives me:
  27521.  
  27522.     array('c', 'Hello World!')
  27523.  
  27524.  
  27525. The need for this "drop replacable" behaviour is more obvious for 
  27526. string-like objects than for other sequence types, but I can think
  27527. or other cases where we would like our replacement-classes to do 
  27528. a good job of impersonating their antecedents. But clearly, at other
  27529. times, we WANT to either get a self-reproducing string ( like array 
  27530. returns ) or a bracketed type representation ( sort of like the way
  27531. files are represented : "<open file '<stdin>', mode 'r' at 20083d98>" )
  27532.  
  27533.  
  27534. I assert that this sort of problem is just the place to distinguish 
  27535. between the strings returned by 'str()' and 'repr()' and I propose
  27536. that we agree ( and document ) some conventions on how they are 
  27537. distinguished. 
  27538.  
  27539. My feeling is that the repr() of an object is the thing that should 
  27540. always be it's "true" representation, but the str() of an object 
  27541. should be it's most useful and convenient representation - i.e. the
  27542. one that minimizes (and hides) what may be non-essential differences
  27543. in classes and objects. 
  27544.  
  27545. Thus:
  27546.  
  27547.     >>>repr( array( 'f', [ 1,2,3,4,5 ] ) )
  27548.  
  27549. would be:
  27550.  
  27551.     array('f', [1.0, 2.0, 3.0, 4.0, 5.0])
  27552.  
  27553. but:
  27554.  
  27555.     >>>str( array( 'f', [ 1,2,3,4,5 ] ) )
  27556.  
  27557. would be:
  27558.  
  27559.     [1.0, 2.0, 3.0, 4.0, 5.0]
  27560.  
  27561.  
  27562. And:
  27563.     >>>repr(array( 'c', 'Hello World' ))
  27564.  
  27565. would be:
  27566.     array( 'c', 'Hello World' )
  27567.  
  27568. but:
  27569.     >>>str(array( 'c', 'Hello World' ))
  27570.  
  27571. would be, simply:
  27572.  
  27573.     'Hello World'
  27574.  
  27575.  
  27576. I suspect it might also be useful in other (non-sequence) classes to 
  27577. distinguish between the representation that hides differences in
  27578. implementation, and the representation that asserts those details.
  27579.  
  27580.  
  27581. I think this proposal is in accord with current usage and how 
  27582. 'print' works, and how 'str()' and 'repr()' currently distinguish
  27583. some objects. ( i.e. I *Don't* think anyone is going to propose that
  27584. it be the other way around entirely! ) 
  27585.  
  27586. Does anyone see any problems with it ? 
  27587. Would anyone expect this sort of change to 'array' to produce 
  27588. much broken code ? 
  27589.  
  27590.  
  27591. - Steve Majewski       (804-982-0831)      <sdm7g@Virginia.EDU>
  27592. - UVA Department of Molecular Physiology and Biological Physics
  27593.  
  27594. 
  27595. 
  27596. Replied: Thu, 04 Nov 1993 11:17:34 +0100
  27597. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> "
  27598. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  27599.     id AA21596 (5.65b/%I%/CWI-Amsterdam); Wed, 3 Nov 1993 19:04:31 +0100
  27600. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa19108;
  27601.           3 Nov 93 13:04 EST
  27602. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  27603.     id AA11944; Wed, 3 Nov 1993 13:04:24 -0500
  27604. Date: Wed, 3 Nov 1993 13:04:24 -0500
  27605. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27606. Message-Id: <199311031804.AA11944@elvis.med.Virginia.EDU>
  27607. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  27608. To: python-list@cwi.nl
  27609. Subject: and one tiny question about array()  ... 
  27610.  
  27611.  
  27612. >>> array( 'f', ( 1.0, 2.0 ))
  27613. Stack backtrace (innermost last):
  27614.   File "<stdin>", line 1
  27615. TypeError: array initializer must be list or string
  27616.  
  27617. Is there a reason for this restriction, or is this another
  27618. example of "overly pedantic typechecking run amock" ? 
  27619.  
  27620. No offense intended to the author of the array module 
  27621. in either this or the previous post. I'm just trying
  27622. to raise the question of exactly what sort of consistant
  27623. behaviour we should expect. 
  27624.  
  27625. - Steve Majewski <sdm7g@Virginia.EDU>
  27626.  
  27627. 
  27628. 
  27629. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27630. Subject: Re: and one tiny question about array() ... 
  27631. In-reply-to: Your message of "Wed, 03 Nov 1993 13:04:24 MET."
  27632.              <199311031804.AA11944@elvis.med.Virginia.EDU> 
  27633. From: Guido.van.Rossum@cwi.nl
  27634. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27635. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27636. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27637. Date: Thu, 04 Nov 1993 11:17:35 +0100
  27638. Sender: guido
  27639.  
  27640. > >>> array( 'f', ( 1.0, 2.0 ))
  27641. > Stack backtrace (innermost last):
  27642. >   File "<stdin>", line 1
  27643. > TypeError: array initializer must be list or string
  27644. > Is there a reason for this restriction, or is this another
  27645. > example of "overly pedantic typechecking run amock" ? 
  27646.  
  27647. It was just easier to code it with a particular concrete type in mind.
  27648. I guess someday many of these restrictions will be lifted...
  27649.  
  27650. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27651. 
  27652. 
  27653. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27654. cc: python-list
  27655. Subject: Re: str() and repr() of sequence like classes, esp. 'array' [RFC] 
  27656. In-reply-to: Your message of "Wed, 03 Nov 1993 12:28:35 MET."
  27657.              <199311031728.AA19031@elvis.med.Virginia.EDU> 
  27658. From: Guido.van.Rossum@cwi.nl
  27659. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27660. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27661. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27662. Date: Thu, 04 Nov 1993 11:22:05 +0100
  27663. Sender: guido
  27664.  
  27665. Steven proposes that all objects have two methods: one for repr() (and
  27666. ``) which returns something unambiguous, and one for str() which
  27667. returns a pleasant string to be used by the print statement.  I like
  27668. the idea.  It would seem to be simple to implement as well.  Thanks!
  27669.  
  27670. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27671. 
  27672. 
  27673. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27674.     id AA02665 (5.65b/%I%/CWI-Amsterdam); Thu, 4 Nov 1993 11:22:05 +0100
  27675. Received: by voorn.cwi.nl with SMTP
  27676.     id AA06485 (5.65b/3.8/CWI-Amsterdam); Thu, 4 Nov 1993 11:22:05 +0100
  27677. Message-Id: <9311041022.AA06485=guido@voorn.cwi.nl>
  27678. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27679. Cc: python-list@cwi.nl
  27680. Subject: Re: str() and repr() of sequence like classes, esp. 'array' [RFC] 
  27681. In-Reply-To: Your message of "Wed, 03 Nov 1993 12:28:35 MET."
  27682.              <199311031728.AA19031@elvis.med.Virginia.EDU> 
  27683. From: Guido.van.Rossum@cwi.nl
  27684. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27685. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27686. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27687. Date: Thu, 04 Nov 1993 11:22:05 +0100
  27688. Sender: Guido.van.Rossum@cwi.nl
  27689.  
  27690. Steven proposes that all objects have two methods: one for repr() (and
  27691. ``) which returns something unambiguous, and one for str() which
  27692. returns a pleasant string to be used by the print statement.  I like
  27693. the idea.  It would seem to be simple to implement as well.  Thanks!
  27694.  
  27695. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27696. 
  27697. 
  27698. Replied: Fri, 05 Nov 1993 10:51:37 +0100
  27699. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> python-list"
  27700. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  27701.     id AA11697 (5.65b/%I%/CWI-Amsterdam); Thu, 4 Nov 1993 18:32:34 +0100
  27702. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa27254;
  27703.           4 Nov 93 12:32 EST
  27704. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  27705.     id AA18831; Thu, 4 Nov 1993 12:32:22 -0500
  27706. Date: Thu, 4 Nov 1993 12:32:22 -0500
  27707. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27708. Message-Id: <199311041732.AA18831@elvis.med.Virginia.EDU>
  27709. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  27710. To: python-list@cwi.nl
  27711. Subject: More nits to pick with arrays ... 
  27712. Cc: Guido.van.Rossum@cwi.nl
  27713.  
  27714.  
  27715. Note that:
  27716.  type(array('f')) == type(array('l')) == <type 'array'>
  27717.  
  27718.  
  27719. >>> from array import array
  27720. >>> f = array( 'f', range( 1, 10 ))
  27721. >>> l = array( 'l', range( 1, 10 ))
  27722. >>> h = array( 'h', range( 1, 10 ))
  27723. >>> h
  27724. array('h', [1, 2, 3, 4, 5, 6, 7, 8, 9])
  27725. >>> h[:3]
  27726. array('h', [1, 2, 3])
  27727. >>> h[-3:]
  27728. array('h', [7, 8, 9])
  27729. >>> h[:3] + h[-3:]                    #1
  27730. array('h', [1, 2, 3, 1, 2, 3])                #2 
  27731. >>> f[:3] + l[-3:]                    #3
  27732. Stack backtrace (innermost last):
  27733.   File "<stdin>", line 1
  27734. TypeError: illegal argument type for built-in operation
  27735. >>> 
  27736.  
  27737.  
  27738. Note that the statement marked #1 makes sense, but the answer
  27739. ( #2 ) is incorrect. 
  27740. Expression #3 doesn't really make any sense when you understand 
  27741. the rationale of array types, but considering the relation at
  27742. the top of the page, a PROGRAM ( as opposed to a reasonable 
  27743. person ) would have every right to expect it to work and NOT
  27744. generate that exception. ( Let's assume that the program has
  27745. tested type(arg1) == type(arg2) and that arg1 and arg2 both
  27746. have the __getslice__ attribute, etc. ) 
  27747.  
  27748.  
  27749. What are the pro's and con's of making:
  27750.     type(array('f')) == <type 'array-f'>
  27751.     type(array('l')) == <type 'array-l'>
  27752.     ... etc.
  27753.  
  27754.  
  27755. - Steve M.
  27756.  
  27757. 
  27758. 
  27759. Replied: Fri, 05 Nov 1993 10:29:13 +0100
  27760. Replied: ""Steven D. Majewski" <sdm7g@elvis.med.virginia.edu> "
  27761. Received: from uvaarpa.Virginia.EDU by charon.cwi.nl with SMTP
  27762.     id AA12241 (5.65b/%I%/CWI-Amsterdam); Thu, 4 Nov 1993 18:57:07 +0100
  27763. Received: from elvis.med.virginia.edu by uvaarpa.virginia.edu id aa02326;
  27764.           4 Nov 93 12:57 EST
  27765. Received: by elvis.med.Virginia.EDU (5.65c/1.34)
  27766.     id AA18795; Thu, 4 Nov 1993 12:56:59 -0500
  27767. Date: Thu, 4 Nov 1993 12:56:59 -0500
  27768. From: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27769. Message-Id: <199311041756.AA18795@elvis.med.Virginia.EDU>
  27770. X-Mailer: Mail User's Shell (7.2.3 5/22/91)
  27771. To: python-list@cwi.nl
  27772. Subject: posix.listdir() broken ? 
  27773.  
  27774. On my build of Python 0.9.9 on AIX, posix.listdir() 
  27775. ( and I think maybe a few other posix functions ) 
  27776. is broken: 
  27777.  
  27778. Python 0.9.9 (Sep  7 1993).
  27779. Copyright 1990, 1991, 1992, 1993 Stichting Mathematisch Centrum,
  27780. Amsterdam
  27781. >>> import posix
  27782. >>> posix.listdir( '' )
  27783. Segmentation fault(coredump)
  27784. elvis: /home/sdm7g/python $ python
  27785. Python 0.9.9 (Sep  7 1993).
  27786. Copyright 1990, 1991, 1992, 1993 Stichting Mathematisch Centrum,
  27787. Amsterdam
  27788. >>> import posix
  27789. >>> posix.listdir( '.' )
  27790. Segmentation fault(coredump)
  27791. elvis: /home/sdm7g/python $ 
  27792.  
  27793.  
  27794. Has anyone else observed a problem ? or is my build on AIX 
  27795. merely but profoundly broken ?  
  27796.  
  27797. - Steve M.
  27798.  
  27799.  
  27800. - Steve Majewski       (804-982-0831)      <sdm7g@Virginia.EDU>
  27801. - UVA Department of Molecular Physiology and Biological Physics
  27802. 
  27803. 
  27804. Received: from inesc.inesc.pt by charon.cwi.nl with SMTP
  27805.     id AA15224 (5.65b/3.12/CWI-Amsterdam); Thu, 4 Nov 1993 23:15:37 +0100
  27806. Received: by inesc.inesc.pt via PTUnet/EUnet;
  27807.     id AB08180 (5.65c/SunOS4.1.3); Thu, 4 Nov 1993 23:15:00 +0100
  27808. Date: Thu, 4 Nov 1993 23:15:00 +0100
  27809. From: MAILER-DAEMON@inesc.inesc.pt (Mail Delivery Subsystem)
  27810. Subject: Returned mail: User unknown
  27811. Message-Id: <199311042215.AB08180@inesc.inesc.pt>
  27812. To: guido@cwi.nl
  27813.  
  27814.    ----- Transcript of session follows -----
  27815. While talking to sabrina.inesc.pt:
  27816. >>> RCPT To:<jmp@sabrina>
  27817. <<< 550 <jmp@sabrina>... User unknown
  27818. 550 <jmp@sabrina.inesc.pt>... User unknown
  27819.  
  27820.    ----- Unsent message follows -----
  27821. Received: from charon.cwi.nl by inesc.inesc.pt with SMTP;
  27822.     id AA19963 (5.65c/SunOS4.1.3); Thu, 4 Nov 1993 13:26:49 +0100
  27823. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27824.     id AA02665 (5.65b/%I%/CWI-Amsterdam); Thu, 4 Nov 1993 11:22:05 +0100
  27825. Received: by voorn.cwi.nl with SMTP
  27826.     id AA06485 (5.65b/3.8/CWI-Amsterdam); Thu, 4 Nov 1993 11:22:05 +0100
  27827. Message-Id: <9311041022.AA06485=guido@voorn.cwi.nl>
  27828. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27829. Cc: python-list@cwi.nl
  27830. Subject: Re: str() and repr() of sequence like classes, esp. 'array' [RFC] 
  27831. In-Reply-To: Your message of "Wed, 03 Nov 1993 12:28:35 MET."
  27832.              <199311031728.AA19031@elvis.med.Virginia.EDU> 
  27833. From: Guido.van.Rossum@cwi.nl
  27834. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27835. X-Address: P.O. Box 4079, 1009 AB  Amsterdam, The Netherlands
  27836. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27837. Date: Thu, 04 Nov 1993 11:22:05 +0100
  27838. Sender: Guido.van.Rossum@cwi.nl
  27839.  
  27840. Steven proposes that all objects have two methods: one for repr() (and
  27841. ``) which returns something unambiguous, and one for str() which
  27842. returns a pleasant string to be used by the print statement.  I like
  27843. the idea.  It would seem to be simple to implement as well.  Thanks!
  27844.  
  27845. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27846. 
  27847. 
  27848. Replied: Fri, 05 Nov 1993 10:55:35 +0100
  27849. Replied: "Bill Janssen <janssen@parc.xerox.com> "
  27850. Received: from alpha.Xerox.COM by charon.cwi.nl with SMTP
  27851.     id AA17637 (5.65b/3.12/CWI-Amsterdam); Fri, 5 Nov 1993 02:17:18 +0100
  27852. Received: from holmes.parc.xerox.com ([13.1.100.162]) by alpha.xerox.com with SMTP id <11756(2)>; Thu, 4 Nov 1993 17:16:55 PST
  27853. Received: by holmes.parc.xerox.com id <16134>; Thu, 4 Nov 1993 17:16:44 -0800
  27854. Received: from Messages.7.15.N.CUILIB.3.45.SNAP.NOT.LINKED.holmes.parc.xerox.com.sun4.41
  27855.           via MS.5.6.holmes.parc.xerox.com.sun4_41;
  27856.           Thu,  4 Nov 1993 17:16:39 -0800 (PST)
  27857. Message-Id: <8gqOZrEB0KGWE2rRJq@holmes.parc.xerox.com>
  27858. Date:     Thu, 4 Nov 1993 17:16:39 PST
  27859. Sender: Bill Janssen <janssen@parc.xerox.com>
  27860. From: Bill Janssen <janssen@parc.xerox.com>
  27861. To: python-list@cwi.nl
  27862. Subject: No event for Control-Space
  27863.  
  27864. I don't get an STDWIN event for control-space.  Seems to me I should get
  27865. an event of type WE_CHAR, with detail = 0.  Or perhaps WE_KEY, detail =
  27866. (32, 8).
  27867.  
  27868. I also seem to get Backspace (control-H) (or WE_CHAR, detail = 7) events
  27869. for Delete.
  27870.  
  27871. Bill
  27872. 
  27873. 
  27874. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27875. Subject: Re: posix.listdir() broken ? 
  27876. In-reply-to: Your message of "Thu, 04 Nov 1993 12:56:59 MET."
  27877.              <199311041756.AA18795@elvis.med.Virginia.EDU> 
  27878. From: Guido.van.Rossum@cwi.nl
  27879. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27880. X-Address: P.O. Box 94079, 1090 GB Amsterdam, The Netherlands
  27881. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27882. Date: Fri, 05 Nov 1993 10:29:13 +0100
  27883. Sender: guido
  27884.  
  27885. > Python 0.9.9 (Sep  7 1993).
  27886. > Copyright 1990, 1991, 1992, 1993 Stichting Mathematisch Centrum,
  27887. > Amsterdam
  27888. > >>> import posix
  27889. > >>> posix.listdir( '.' )
  27890. > Segmentation fault(coredump)
  27891. > elvis: /home/sdm7g/python $ 
  27892. > Has anyone else observed a problem ? or is my build on AIX 
  27893. > merely but profoundly broken ?  
  27894.  
  27895. I've never seen this before; sounds like a problem with your build or
  27896. with AIX...
  27897.  
  27898. --Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
  27899. 
  27900. 
  27901. Received: from voorn.cwi.nl by charon.cwi.nl with SMTP
  27902.     id AA23403 (5.65b/3.12/CWI-Amsterdam); Fri, 5 Nov 1993 10:51:38 +0100
  27903. Received: by voorn.cwi.nl with SMTP
  27904.     id AA13476 (5.65b/3.8/CWI-Amsterdam); Fri, 5 Nov 1993 10:51:37 +0100
  27905. Message-Id: <9311050951.AA13476=guido@voorn.cwi.nl>
  27906. To: "Steven D. Majewski" <sdm7g@elvis.med.virginia.edu>
  27907. Cc: python-list@cwi.nl
  27908. Subject: Re: More nits to pick with arrays ... 
  27909. In-Reply-To: Your message of "Thu, 04 Nov 1993 12:32:22 MET."
  27910.              <199311041732.AA18831@elvis.med.Virginia.EDU> 
  27911. From: Guido.van.Rossum@cwi.nl
  27912. X-Organization: CWI (Centrum voor Wiskunde en Informatica)
  27913. X-Address: P.O. Box 94079, 1090 GB Amsterdam, The Netherlands
  27914. X-Phone: +31 20 5924127 (work), +31 20 6225521 (home), +31 20 5924199 (fax)
  27915. Date: Fri, 05 Nov 1993 10:51:37 +0100
  27916. Sender: Guido.van.Rossum@cwi.nl
  27917.  
  27918. > Note that:
  27919. >  type(array('f')) == type(array('l')) == <type 'array'>
  27920.  
  27921. This merely means that the objects share most of the C code
  27922. implementing them...
  27923.  
  27924. > >>> from array import array
  27925. > >>> f = array( 'f', range( 1, 10 ))
  27926. > >>> l = array( 'l', range( 1, 10 ))
  27927. > >>> h = array( 'h', range( 1, 10 ))
  27928. > >>> h
  27929. > array('h', [1, 2, 3, 4, 5, 6, 7, 8, 9])
  27930. > >>> h[:3]
  27931. > array('h', [1, 2, 3])
  27932. > >>> h[-3:]
  27933. > array('h', [7, 8, 9])
  27934. > >>> h[:3] + h[-3:]                    #1
  27935. > array('h', [1, 2, 3, 1, 2, 3])            #2 
  27936. > >>> f[:3] + l[-3:]                    #3
  27937. > Stack backtrace (innermost last):
  27938. >   File "<stdin>", line 1
  27939. > TypeError: illegal argument type for built-in operation
  27940. > >>> 
  27941. > Note that the statement marked #1 makes sense, but the answer
  27942. > ( #2 ) is incorrect. 
  27943.  
  27944. #2 is a bug!  Thanks for reporting this.  It's fixed in 1.0...
  27945.  
  27946. > Expression #3 doesn't really make any sense when you understand 
  27947. > the rationale of array types, but considering the relation at
  27948. > the top of the page, a PROGRAM ( as opposed to a reasonable 
  27949. > person ) would have every right to expect it to work and NOT
  27950. > generate that exception. ( Let's assume that the program has
  27951. > tested type(arg1) == type(arg2) and that arg1 and arg2 both
  27952. > have the __getslice__ attribute, etc. ) 
  27953. > What are the pro's and con's of making:
  27954. >     type(array('f')) == <type 'array-f'>
  27955. >     type(array('l')) == <type 'array-l'>
  27956. >     ... etc.
  27957.  
  27958. This would be awkward, since these types all share the same
  27959. implementation.  Especially since I am hoping to generalize the array
  27960. type to support arrays of arbitrary structures.  It is no coincidence
  27961. that the format string uses the same letters as the 'struct' module.
  27962.  
  27963. I don't think that in general a program can make some superficial
  27964. tests on an object and then assume to know all its properties.  In
  27965. this case, the array type enforces an